Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop enumerateObjectsUsingBlock Swift

How do I stop a block enumeration?

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

I know in obj-c you do this:

    [myArray enumerateObjectsUsingBlock:^(id *myObject, NSUInteger idx, BOOL *stop) {         *stop = YES;     }]; 
like image 584
random Avatar asked Jun 13 '14 21:06

random


2 Answers

This has unfortunately changed every major version of Swift. Here's a breakdown:

Swift 1

stop.withUnsafePointer { p in p.memory = true } 

Swift 2

stop.memory = true 

Swift 3

stop.pointee = true 
like image 153
Sam Soffes Avatar answered Nov 10 '22 02:11

Sam Soffes


In Swift 1:

stop.withUnsafePointer { p in p.memory = true } 

In Swift 2:

stop.memory = true 

In Swift 3 - 4:

stop.pointee = true 
like image 23
Christian Dietrich Avatar answered Nov 10 '22 01:11

Christian Dietrich