理解NSString比较以下两种比较结果均为真:1)@"foo" == @"foo";2)NSString *myString1 = @"foo";NSString *myString2 = @"foo";myString1 == myString2;但是,肯定有两次NSStringS不能使用相等运算符进行比较,并且[myString1 isEqualToString:myString2]是必需的。有人能解释一下这件事吗?
3 回答
互换的青春
TA贡献1797条经验 获得超6个赞
==
NSString
@""
NSString
isEqualToString:
NSString *myString1 = @"foo";NSString *myString2 = @"foo";NSString *myString3 = [[NSString alloc] initWithString:@"foo"]; NSLog(@"%d", (myString2 == myString3)) //0NSLog(@"%d", (myString1 == myString2)); //1NSLog(@"%d", [myString1 isEqualToString:myString2]); //1NSLog(@"%d", [myString1 isEqualToString:myString3]); //1[myString3 release];
NSString *myString3 = [[NSString alloc] initWithString:@"foo"]; // this is same with @"foo"
initWithString:
initWithFormat
,
NSString *myString3 = [[NSString alloc] initWithFormat:@"foo"];
弑天下
TA贡献1818条经验 获得超8个赞
==
@""
isEqual:
isEqual:
isEqualToString:
isEqualToString:
慕桂英546537
TA贡献1848条经验 获得超10个赞
==
ptr == ptr2
isEqualToString
- 3 回答
- 0 关注
- 628 浏览
添加回答
举报
0/150
提交
取消