【发布时间】:2015-04-11 10:38:08
【问题描述】:
这是在 Swift 1.1 中完美运行的代码
在我的课开始时,我有
var bytes = [UInt8]?()
后来我有
func hexString() -> String? {
if let b = bytes {
return b.map({NSString(format: "%02x", $0)}).reduce("", +)
}
return nil
}
Swift 1.2 给了我
调用中缺少参数标签“combine:”
因此希望我以这种方式改写我的地图减少
return b.map({NSString(format: "%02x", $0)}).reduce("", combine: +)
注意第二个reduce 参数的显式combine。如果我这样做,尽管我在+ 上遇到另一个错误:
找不到接受所提供参数的“+”重载
这个错误对我来说毫无意义,因为 NSString(format:) 产生的是一个 NSString,所以它应该与 + 一起使用,对吧?
【问题讨论】:
标签: cocoa swift mapreduce nsstring operator-overloading