我想知道swift编译器为什么不接受:
let closestStationAnnotations = closestAnnotations.filter({let closestStationAnnotations = closestAnnotations.filter({ (annotation : MKAnnotation) -> Bool in annotation.dynamicType === StationAnnotation.self }).dynamicType === StationAnnotation.self })
无法转换类型(_)的值 – > Bool到期望参数类型(MKAnnotation) – >布尔
但接受:
let closestStationAnnotations = closestAnnotations.filter({解决方法 我一直在尝试不同版本的代码(使用Xcode 7).使用时,修复是显而易见的let closestStationAnnotations = closestAnnotations.filter({ print("\(is StationAnnotation})let closestStationAnnotations = closestAnnotations.filter({ return ()") return (.dynamicType === StationAnnotation.self)})let closestStationAnnotations = closestAnnotations.filter({ return true}).dynamicType === StationAnnotation.self)})
这是测试类型的正确方法,没有任何问题.
我注意到有一些简单的代码可以使错误消失
但是,这不起作用:
如果您注意到错误消息,编译器会将闭包视为(_) – >布尔.
这使我得出结论,表达式$0.dynamicType以某种方式被优化出来.
最有趣的是
会触发相同的错误.
所以我认为有两个编译器错误:
>编译器无法从数组类型推断出参数,这是错误的,因为(_) – > Bool应被视为(类型) – > Bool在[Type]上调用时.>编译器以某种方式优化$0.dynamicType out,这显然是错误的.
总结以上是内存溢出为你收集整理的为什么swift编译器有时不接受速记参数名称?全部内容,希望文章能够帮你解决为什么swift编译器有时不接受速记参数名称?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)