在 Swift 2.2 之前,我可以通过使用 var 使 stop 参数可变,然后进行适当的设置来停止枚举stop = UnsafeMutablePointer<ObjCBool>.alloc(NSNumber(bool: true).integerValue)
现在,在 2.2 中,不推荐使参数可变,那么如何停止枚举呢?
你的语法很奇怪;-)
\n\n这适用于 Swift 2.1 和 2.2
\n\nlet array: NSArray = [1, 2, 3, 4, 5]\narray.enumerateObjectsUsingBlock { (object, idx, stop) in\n print(idx)\n if idx == 3 {\n stop.memory = true\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n斯威夫特3:
\n\nlet array: NSArray = [1, 2, 3, 4, 5]\narray.enumerateObjects({ (object, idx, stop) in\n print(idx)\n if idx == 3 {\n stop.pointee = true\n }\n})\nRun Code Online (Sandbox Code Playgroud)\n\n尽管如此, \xe2\x80\x93\xc2\xa0 正如其他答案 \xe2\x80\x93\xc2\xa0 使用本机 Swift 中所建议的那样Array。
| 归档时间: |
|
| 查看次数: |
1671 次 |
| 最近记录: |