IOS basics-Four Range types of instance variables and four types of ios instance variables

Source: Internet
Author: User

IOS basics-Four Range types of instance variables and four types of ios instance variables

1. to force an object to hide its data, the compiler limits the scope of instance variables to restrict its visibility in the program.

However, to provide flexibility, Apple also allows developers to display the Set range (select one from four ).

2. Four compilation commands are as follows:

@ Private

Instance variables can only be accessed by declared classes.

 

@ Protected

The instance variable can be declared as its class and subclass. All instance variables that do not display a specified range are @ protected.

 

@ Public

Instance variables can be accessed anywhere.

 

@ Packge

When modern is used for running, a @ package instance variable is actually @ public in the executable file image implementing this class, but it is @ private outside.

The @ package in OC is similar to the variables in C language and the private_extern of the function. Any image other than the implementation class image that wants to use this instance variable will cause link error.

This type is most commonly used for instance variables of the framework class. @ private is too restrictive and @ protected or @ public is too open.

 

 

 

 

 

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.