NSSet with NSNumber ignores isEqual and adds duplicate objects (32 bits only)
| Originator: | santusmarc | ||
| Number: | rdar://10368305 | Date Originated: | Sun Oct 30 2011 |
| Status: | Open | Resolved: | |
| Product: | Mac OS X SDK | Product Version: | 10.7.2 |
| Classification: | Serious bug | Reproducible: | Always |
See test project here: http://dl.dropbox.com/u/366830/Bugs/nsseterror.zip
Summary:
When running in 32 bit mode, (including on iOS), NSSet adds duplicate NSNumbers with equivalent values (isEqual returns YES on both added objects).
The NSSet documentation is somewhat ambiguous about what method it uses to decide object uniqueness in the collection.
Steps to Reproduce:
1) Please see attached test project
2) See this code for an overview
NSSet *testSet = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithBool:1], nil];
NSLog(@"Test set %@", testSet);
Actual results:
NSLog(@"Test set %@", testSet);
Output, 2011-10-30 01:25:06.507 nsseterror[56108:707] Test set {(
1,
1
)}
Expected results
2011-10-30 01:19:47.706 nsseterror[56084:707] Test set {(
1
)}
Notes:
([[NSNumber numberWithBool:YES] isEqual:[NSNumber numberWithInt:1]])
Evaluates to YES on both 64 bit and 32 bit
This affects NSCountedSet as well.
I found this bug while using an NSCountedSet with countForObject trying to find NSNumbers created by Core Data booleans and finding that numberWithInt would work (returned the right object count) but not numberWithBool (returned 0)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!