Swift 2.2 enumerateObjectsUsingBlock - 停止

Ric*_*ins 2 ios swift

在 Swift 2.2 之前,我可以通过使用 var 使 stop 参数可变,然后进行适当的设置来停止枚举stop = UnsafeMutablePointer<ObjCBool>.alloc(NSNumber(bool: true).integerValue)

现在,在 2.2 中,不推荐使参数可变,那么如何停止枚举呢?

vad*_*ian 5

你的语法很奇怪;-)

\n\n

这适用于 Swift 2.1 和 2.2

\n\n
let 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}\n
Run Code Online (Sandbox Code Playgroud)\n\n

斯威夫特3:

\n\n
let 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})\n
Run Code Online (Sandbox Code Playgroud)\n\n

尽管如此, \xe2\x80\x93\xc2\xa0 正如其他答案 \xe2\x80\x93\xc2\xa0 使用本机 Swift 中所建议的那样Array

\n