Tuesday, June 5, 2012

CCArray containsObject does not work with NSNumber

I tried the following code, and containsObject does not seem to return true for CCArray:


CCArray* test = [CCArray array];
[test addObject:[NSNumber numberWithInt:99]];
if ([test containsObject:[NSNumber numberWithInt:99]]) {
  NSLog(@"it works");
}
else {
  NSLog(@"Something is wrong!");
}


This is because CCArray compares pointers.  See: http://www.cocos2d-iphone.org/forum/topic/12760

No comments:

Post a Comment