I might be missing something. But my current app on the appstore works in iOS 7, but in iOS 8 completely fails because it won't create a preallocated pool of sprites. They appear to be written to the same address unless the sprites have specifically different properties.
In iOS 7 the following code produces a set with 4 unique objects. In iOS 8, the same code produces a set with only 1 object:
NSMutableSet *aSet = [NSMutableSet set];
SKColor *sameColor = [SKColor redColor];
CGSize sameSize = CGSizeMake(10, 10);
for (int i = 0; i < 4; i++) {
//allocate a brand new sprite
SKSpriteNode *thisSprite1 = [[SKSpriteNode alloc] initWithColor:sameColor size:sameSize];
[aSet addObject:thisSprite1];
}
NSLog(@"aSet Count: %i", aSet.count);
iOS8 Result:
2014-09-09 15:06:43.065 MSM[383:27490] aSet Count: 1
Am I going crazy? Amazingly, pretty much my entire app is based on this code concept repeated over and over again. If I do the same thing, but use something like NSObject
, then the problem goes away, so it appears to be a new change to SKSprite
. I know I can work around it with some crazy stuff, but is a huge pain, since I shouldn't have to do that, and I was hoping to avoid another version submission.
isEqual:
is not (necessarily) a comparison of addresses. It is for semantic comparison; each class implements it to define what "equality" is for its particular properties. – JandyNSSet
uses-hash
and-isEqual:
to determine membership. That still doesn't have anything to do with the memory addresses of the sprites. It just means that the implementation of-[SKSprite isEqual:]
was changed between iOS 7 and 8, possibly away from comparing addresses and to comparing member data. – JandyNSSet
? Why not an array? – Jandy-[NSArray indexOfObjectIdenticalTo:]
will tell you if an object with the same address exists in the array already. Or you could subclassSKSpriteNode
to re-implement address comparison inisEqual:
– Jandy