IOS methods and self

Source: Internet
Author: User

In objective-C, there are both instance methods and class methods. Class methods are sometimes called factory methods or convenience methods ). Factory methods are obviously different from factory methods in the general sense. In essence, class methods can be executed independently of objects, therefore, in other languages, surface methods are sometimes called static methods.
Note 1: class methods
1. Class methods can call class methods.
2. The class method cannot call the instance method, but the class method can access the instance method by creating an object.
3. instance variables cannot be used for class methods. Class methods can use self, because self is not an instance variable.
4. Class methods as messages can be sent to classes or objects (in fact, class methods can be called through classes or objects ).
NOTE 2: Self rules
Remember the following rules:
1. Self In the instance method is the first address of the object.
2. self in the class method is class.
Although self is used in the same class, self has different interpretations. Self in the class method can be translated into class self; self in the instance method should be translated into object self. The self in the class method is essentially different from the self in the instance method, even though their names are all self.

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.