0

I am attempting to use enumerateChildNodesUsingBlock() where I set stop to true so the enumeration will ignore child nodes. There is a similar question: How to use "enumerateChildNodesWithName" with Swift in SpriteKit? But nothing I try sets stop to true. Maybe something different is needed in Swift 2.0?

EDIT: I found a video relating to a similar enumeration. Evidently stop.memory = true belongs further along in the body of the closure as opposed to modifing the first use of stop.

Community
  • 1
  • 1
bpedit
  • 1,176
  • 8
  • 22

2 Answers2

3

I'm not a user of SpriteKit, so I may be wrong here, but if stop is an UnsafeMutablePointer<ObjCBool> object, you can set its value like this:

stop[0] = true

inside the closure to stop the enumeration.

I believe it should also work with

stop.memory = true

but for some reason this doesn't work for me when testing with different but similar methods (enumerateSubstringsInRange for example).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    Thanks Eric. Your bottom method worked for me when I finally put it in the body of the closure after the `in` instead of trying to assign it to `stop` before the `in`. It turned out to be usless for me as I was trying to select a bunch of nodes on the same level while ignoring their children. This operation seems only to select one node. No matter, iterating an array instead of enumerating a tree was a much faster solution. Thanks again. – bpedit Feb 09 '16 at 18:11
0

In objective C its something like *stop = YES in case someone came in here looking for an answer

  • Thanks, but I'm working in Swift. I've tried some versions of objC since that's what the "stop" seems to want from the description but to no avail. – bpedit Feb 07 '16 at 22:40