1

My question, is very simple I think, but I can't find any direct info to confirm or deny.

My question is:

When enumeration thru SKNodes, should they be treated delicately using:

SKNode *someTreeNode;
NSArray *someArray = [someTreeNode children];

        [someArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

//blah blah

}];

Like NSMutableArray?

If you are using GCD and manipulating the SKNode (someTreeNode), i.e. adding and removing parent? (in addition I could use dispatch barriers to block while loading someArray.

But all in all the real lowest form of this question is:

Is SKNode thread safe like NSArray, or is it unsafe like NSMutableArray?

My instinct tells me it's unsafe but like I said I cannot confirm or deny this...

Thanks

rezwits
  • 835
  • 7
  • 12
  • It's simple. The question is: is the object mutable or immutable? Even enumerating `NSArray` is only thread-safe from the perspective of the container. There's nothing to prevent objects within the array from being changed from multiple, concurrent threads. – Avi Aug 03 '16 at 04:36
  • After going back and forth changing my enumerations from NSArray enumerations to SKNode enumerations, I don't have crashes while doing SKNode enumerations. So on my end I am going to call them "safe" unless I get into some crashes again, which I haven't gotten yet. The reason I asked this question was, I was working with some NSMutableArrays and got into some serious enumeration errors over the weekend. I debugged them and I started thinking about SKNode and used the children array. Now I have reverted them back to standard enumeration methods, not using Children Array, and they're fine! – rezwits Aug 03 '16 at 16:05

1 Answers1

0

When using, GCD (Grand Central Dispatch(es)) with the block processing calls:

    [someMutableArray enumerateObjectsUsingBlock:^(id  _Nonnull obj,
                                    NSUInteger idx, BOOL * _Nonnull stop) {
        //some code
    }];

or

    [someTreeNode enumerateChildNodesWithName:@"*"
                                   usingBlock:^(SKNode *node, BOOL *stop) {
        //some code
    }];

use caution, an even try not to use at all, especially if using devices using the same processing code, and networked together sharing such objects, via network transfers. You will end up with crashes. i.e. they are not thread safe... if you must, use dispatch_barrier_async, with a dispatch_sync to edit the contents.

rezwits
  • 835
  • 7
  • 12