IOS development ==and equal, iosequal
For common data types, true is returned if the value is equal to =. For two pointer types, they must point to the same pointer variable, that is, they must point to the same address.
Equal and use = to determine whether the two objects are equal.
But sometimes we can return true if the value is equal when comparing strings, because the equal method is overwritten.
For this method, we can define their own equal conditions. All classes inherit from the NSObject class, and we can rewrite this method.
For string comparison, the string also defines an isEqualToString method, which is used to determine the differences between string sequences and so on.
One of the most interesting questions is @ "Who Am I?" And StringWithFormat: @ "Who Am I ". What are the differences between the two?
The differences are as follows:
@ "Who Am I?" refers to the constant pool, which ensures that there is only one direct number of strings and no multiple copies are available.
NSString * s1 = @ "Who am I ";
NSString * s2 = @ "Who am I ";
Print the s1 and s2 address values, and you can find that they are exactly the same
Use StringWithFormat: @ "Who Am I?", which is created at runtime and saved in the runtime memory zone (heap memory) and not in the constant pool, therefore, the address is different from s1 s2.