我正在通过教程学习Swift语言。
我正在使用此代码:
let hasPrefixAndSuffix: (String,String,String) -> Bool
{
var hasPrefix = $0.hasPrefix($1)
var hasSuffix = $0.hasSuffix($2)
return hasPrefix && hasSuffix
}
我发现了这个错误:
Anonymous closure argument not contained in a closure.
答案 0 :(得分:1)
您忘记了=
实际上将该闭包分配给变量。
let hasPrefixAndSuffix: (String,String,String) -> Bool = {
var hasPrefix = $0.hasPrefix($1)
var hasSuffix = $0.hasSuffix($2)
return hasPrefix && hasSuffix
}