Objective-c Access Controller

Source: Internet
Author: User

Objective-c Access Controller

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

@ 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;

}

}

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.