The scope type of a member variable in a class

Source: Internet
Author: User

Scope Type a total of four

1, @public can directly access member variables directly from the member variable name anywhere. (Not recommended)

2, @private can only access member variables directly through the member variable name in the object method of the current class, where it needs to be accessed through the Geter and Seter methods. (The default type of the declared member variable in the @implementation)

3, @protected can only access member variables directly through the member variable name in the object methods of the current class and its subclasses, and it needs to be accessed through the Geter and Seter methods elsewhere. (The default type of the declared member variable in the @interface)

4, @package the member variable of an object can be accessed directly from the member variable name, as long as it is in the same frame. (rarely used, mainly used in framework writing)

Note the point:

1, member variables declared in @interface and @implementation in the same class cannot have the same name.

2, generally no longer declare member variables in @implementation.

3, a member variable declared in a. m file can only be a @private type, even if it is preceded by another scope type @implementation. If the situation differs in other files.

(Self-summary, if there is a mistake wish to point out, thank you)

The scope type of a member variable in a class

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.