Empty NSTaggedPointerString returns YES to isEqualToString:nil
| Originator: | joerick | ||
| Number: | rdar://24344722 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | |
| Classification: | Reproducible: | Always |
Summary:
Empty NSTaggedPointerString returns YES to isEqualToString:nil
An empty NSTaggedPointerString returns YES to isEqualToString:nil. This differs from other NSString implementations, such as __NSCFConstantString.
=code=
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *a = @"";
NSLog(@"a: '%@' %@", a, object_getClass(a));
NSLog(@"[a isEqualToString:nil] => %i", [a isEqualToString:nil]);
NSString *b = [[@"string" mutableCopy] copy];
NSLog(@"b: '%@' %@", b, object_getClass(b));
NSString *c = [b substringWithRange:NSMakeRange(0,0)];
NSLog(@"c: '%@' %@", c, object_getClass(c));
NSLog(@"[c isEqualToString:nil] => %i", [c isEqualToString:nil]);
}
}
=output=
2016-01-26 03:30:43.470 Untitled[82359:4491298] a: '' __NSCFConstantString
2016-01-26 03:30:43.471 Untitled[82359:4491298] [a isEqualToString:nil] => 0
2016-01-26 03:30:43.471 Untitled[82359:4491298] b: 'string' NSTaggedPointerString
2016-01-26 03:30:43.471 Untitled[82359:4491298] c: '' NSTaggedPointerString
2016-01-26 03:30:43.471 Untitled[82359:4491298] [c isEqualToString:nil] => 1
=end=
Steps to Reproduce:
1. Run the above using Xcode 7.1
Expected Results:
I'd expect all members of the NSString class-cluster to behave the same. No string can be equal to nil, so that method should always return NO. -isEqual: returns NO.
Actual Results:
The NSTaggedPointerString returns YES, but other implementations return NO.
Version:
OS X 10.11 (15A284)
Notes:
Currently the workaround is just to use -isEqual:.
Configuration:
Xcode 7.1
Mac OS X 10.11
Attachments:
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!