简体   繁体   English

Swift-闭包中不包含匿名闭包参数

[英]Swift - Anonymous closure argument not contained in a closure

I'm learning the Swift lang with a tutorial. 我正在通过教程学习Swift lang。

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.

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM