Reputation: 1475
I'm learning the Swift lang with a tutorial.
I'm using this code:
let hasPrefixAndSuffix: (String,String,String) -> Bool
{
var hasPrefix = $0.hasPrefix($1)
var hasSuffix = $0.hasSuffix($2)
return hasPrefix && hasSuffix
}
and I've this error:
Anonymous closure argument not contained in a closure.
Upvotes: 0
Views: 3869
Reputation: 187024
You forgot the =
which actually assigns that closure to the variable.
let hasPrefixAndSuffix: (String,String,String) -> Bool = {
var hasPrefix = $0.hasPrefix($1)
var hasSuffix = $0.hasSuffix($2)
return hasPrefix && hasSuffix
}
Upvotes: 1