iOS development = = and equal differences and links

Source: Internet
Author: User
For normal data types, as long as the value equals = = will return true, for two pointer-type variables, they must point to the same pointer variable, that is, they point to the address must be equal.
Equal and using = = To determine whether two objects are equal is no different.
But sometimes when we compare strings, we can return true as long as the values are equal, because the equal method is overridden.

For this method, we can define their own conditions, and all classes inherit from the NSObject class, and we can override this method.

For string comparisons, the string also defines a isequaltostring method that is specifically used to determine the sequence of strings

One problem is most interesting to use @ "Who am I" and stringwithformat:@ "Who am I?" What's the difference between these two?
The difference is as follows:
@ "Who am I?" Using a constant pool, the constant pool guarantees that the string has a direct amount of only one, and there is no more than one copy.
NSString * S1 = @ "Who am I?";
NSString * s2 = @ "Who am I?";
Print out the address values of S1 and S2, and you can find the exact same
Using stringwithformat:@ "Who am I", this is created by the runtime, is saved in the runtime memory area (heap memory), is not placed in the constant pool, so the address and S1 S2 are different.

iOS development = = and equal differences and links

Related Article

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.