enumerateObjectsUsingBlock in Swift

后端 未结 4 1132
孤城傲影
孤城傲影 2021-02-05 02:10

I am trying to iterate through an array using enumerateObjectsUsingBlock to fetch data. How to use enumerateObjectsUsingBlock in Swift ? Please help me with an example.

4条回答
  •  忘了有多久
    2021-02-05 02:31

    I write the extension of CollectionType.

    Any way to stop a block literal in swift

        func forEach(body: ((Self.Generator.Element, Int, inout Bool) -> Void)) {
            var stop = false
            let enumerate = self.enumerate()
            for (index,value) in enumerate {
                if stop { break }
                body(value,index,&stop)
            }
        }
    

提交回复
热议问题