使用 ==
比较 iOS
中的对象时,比较的是对象的指针。例如有如下比较时:
1 2 3 4 5 6 7 8 9
| NSString *str = @"origin1"; NSString *strCopy = [str copy]; NSString *str1 = [NSString stringWithFormat:@"origin%@", @1]; BOOL equalA = (str == strCopy); BOOL equalB = (str == str1);
BOOL equalC = [str isEqualToString:str1]; /**< equalC is YES */ BOOL equalD = [str isEqual:str1]; /**< equalD is YES */
|
Continue reading