How to stop enumerateObjectsUsingBlock Swift

后端 未结 5 512
慢半拍i
慢半拍i 2020-12-14 15:26

How do I stop a block enumeration?

    myArray.enumerateObjectsUsingBlock( { object, index, stop in
        //how do I stop the enumeration in here??
    })         


        
5条回答
  •  抹茶落季
    2020-12-14 16:09

    since XCode6 Beta4, the following way can be used instead:

    let array: NSArray = // the array with some elements...
    
    array.enumerateObjectsUsingBlock( { (object: AnyObject!, idx: Int, stop: UnsafePointer) -> Void in
    
            // do something with the current element...
    
            var shouldStop: ObjCBool = // true or false ...
            stop.initialize(shouldStop)
    
            })
    

提交回复
热议问题