IOS development _.. and self ... The difference and use

Source: Internet
Author: User

Believe that many beginners to _ and self. The difference between the two is not a general understanding, then the difference between the following to do a simple introduction:

As for rewriting the set and get methods, briefly explain that when we use the @property usage, the system automatically gives us a default set and get method for the variables we define. In a word, the difference between _any and Self.any is that _any is only referring to _any itself, which is generated by the system, and if we rewrite the set method of any, Self.any will invoke the contents of our overridden Set method, and _any is not, for example, this sentence

-(void)setCount:(NSUInteger)count{    _count = count;}

This means that the system defaults to our generated count to become our custom count, to achieve the purpose we want.
_any simply means that when we use @property, the system gives me an automatically generated any, Unlike Self.any, which is automatically called (the set and get methods themselves are included, or they can be understood as part of a property of itself) we rewrite the set method, and when we self.any, any content in the overridden set method will be used by us, so even if we only SELF.A NY can also implement many of the effects that are written in the set method, which is roughly the meaning

IOS development _.. and self ... The difference and use

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.