当我alloc和init两个NSString变量比较它们的指针时,它们是相同的。这是一个显示这一点的片段:
NSString *s1 = [[NSString alloc] initWithString:@"hello world"];
NSString *s2 = [[NSString alloc] initWithString:@"hello world"];
if (s1 == s2) {
NSLog(@"==");
}else {
NSLog(@"!=");
}
为什么都s1和s2一样?