Objective-C Access Controller

Source: Internet
Author: User

Four access controllers of member variables in objective-C:

@ PRIVATE: only the current class can be accessed internally.

@ Public: All users can access

@ Protected: only the current class and its subclass can be accessed.

@ Package: allow member variables controlled by the package to be accessed not only in the current class, but also in other programs with the same image.


What is "same image "?

Is the same framework or the same execution file generated after compilation.

That is, the current framework can be accessed, but external programs cannot. (If it is public, external programs can also access it ).


@ Private

@ Package

@ Protected

@ Public

Same type

???

???

???

???

In the same image


???


???

Subclass



???

???

Within the global scope




???


Example:

Interface Section: (fkapple. h)

# Import <Foundation/Foundation. h>

@ Interface fkapple: nsobject

{

// Use @ package to restrict member variables

@ Package

Double _ weight;

}

@ End

Main Section:

# Import "fkapple. H"

Int main (INT argc, char * argv [])

{

@ Autoreleasepool {

Fkapple * Apple = [[fkapple alloc] init];

Apple-& gt; _ Weight = 30.4;

}

}

Objective-C Access Controller

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.