IOS development ==and equal, iosequal

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.