gpt4 book ai didi

ios - Swift 2.2 enumerateObjectsUsingBlock - 停止

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:44 24 4
gpt4 key购买 nike

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

现在在 2.2 中使参数可变已被弃用,那么如何停止枚举?

最佳答案

你的语法很奇怪;-)

这适用于 Swift 2.1 和 2.2

let array: NSArray = [1, 2, 3, 4, 5]
array.enumerateObjectsUsingBlock { (object, idx, stop) in
print(idx)
if idx == 3 {
stop.memory = true
}
}

swift 3:

let array: NSArray = [1, 2, 3, 4, 5]
array.enumerateObjects({ (object, idx, stop) in
print(idx)
if idx == 3 {
stop.pointee = true
}
})

尽管如此——正如其他答案中所建议的——使用原生 Swift Array

关于ios - Swift 2.2 enumerateObjectsUsingBlock - 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com