0
votes

Is it safe to call [n removeFromParent]; after the parent to n has been released (and thus does not exist)?

I guess n.parent will be nil at that point.

Do I have to do something like

if (n.parent != nil)
  [n removeFromParent]; 

For reference:

https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/#//apple_ref/occ/instm/SKNode/removeFromParent

1
I think its safe to call [n removeFromParent]; directly bcos objective-c will able to handle this internally. However for your satisfaction you can check the parent before executing the method [n removeFromParent];. - Vijay Masiwal

1 Answers

0
votes

Yes, I do it all the time. If you want to validate, simply do something like this the next time you call want to do it.

[n removeFromParent];
[n removeFromParent];
[n removeFromParent];
[n removeFromParent];

You'll notice no side effects.