Objective-c How do private variables and private methods work?

Source: Internet
Author: User

Let's say private methods,
Due to the dynamic messaging mechanism of objective-c, there is no real private method in OC.
But if you do not declare in the. h file, only in the. m file, or in the class extension of the. m file, it is basically the same as the private method.

Private variables can be declared by @private, for example

  @interface sample: { @private nsstring * Tteesstt;}  @property  (nonatomic,strong< Span class= "P" >) nsstring *hoge; - (void) foo; @end                 

Then the TTEESSTT variable is private. The property Hoge is the default public.

Apple's official document now uses more property than the direct definition of instance variable. The class extension that defines the property to. M is also basically the same as a private variable.

In a nutshell, put the. h file that you want to have, and put it in the. m file privately. Import only. h files (. m files are also available for import, but we do not generally do so).

Objective-c How do private variables and private methods work?

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.