I’d like to remove a NSNumber from a CCArray. When I use removeObject: to remove a NSNumber of 13 or above nothing gets removed. What’s going on here? I’ve tried using an NSMutableArray and it works fine. Using removeObjectAtIndex: is not an option because my array wont be in numerical order.
CCArray *arr = [CCArray array];
for (NSInteger i = 0; i < 20; i++) {
[arr addObject:[NSNumber numberWithInt:i]];
}
// Outputs arr count 20
CCLOG(@"%@: arr count %i ", NSStringFromSelector(_cmd), [arr count]);
[arr removeObject:[NSNumber numberWithInt:13]];
// Still outputs arr count 20
CCLOG(@"%@: arr count %i ", NSStringFromSelector(_cmd), [arr count]);
I can verify that this seems to be a problem. Although I was able to call removeObject successfully, indexOfObject: returned NSNotFound. I rewrote the test case, and the error was gone. One more reason to stay away from CCArray I suppose.
I suggest to use NSMutableArray in this case. The slightly better performance of CCArray will not be reflected in better framerate, especially not for an array that has 20 elements. Besides, correct code is always better than code that’s faster but incorrect.