Understanding NSString comparison
问题 Both the following comparisons evaluate to true: 1) @\"foo\" == @\"foo\"; 2) NSString *myString1 = @\"foo\"; NSString *myString2 = @\"foo\"; myString1 == myString2; However, there are definitely times where two NSString s cannot be compared using the equality operator, and [myString1 isEqualToString:myString2] is required instead. Can someone shed some light on this? 回答1: The reason why == works is because of pointer comparison. When you define a constant NSString using @"" , the compiler