Objective-C-attributes and member variables are different in. H files and. m files,

Source: Internet
Author: User

Objective-C-attributes and member variables are different in. H files and. m files,
Differences between attributes and member variables in. H files and. m Files

Attribute declaration in. h file is different from in. m file. The difference is:
Attributes declared in the. h file. The external class can be called through "class instance. Attribute,
But it cannot be declared in. m. The methods for obtaining and setting can only be implemented through setValue: forKey and valueForKey.

Member variables have three permissions: @ private, @ protected, and @ public. in the m file, it is equivalent to the @ private permission, and The subclass cannot be accessed. After verification, the permission modification is also invalid. In the. h file, the default permission is @ protected, which can be accessed by subclass and modified by permission. Because of the access permission pointer to the. h file .. The member variable in the H file, called by an external class, is the same as that in C ++.

From: http://blog.sina.com.cn/s/blog_68f368050101eop8.html

@ Interface is extension ).

It is designed to solve two problems,
1. Define private methods.
Second, implement the public readonly and private readwrite property (meaning that an attribute defined in the h header file is readonly for external use, but it is expected to be readable and writable within the class, therefore, you can redefine this attribute as readwrite in the @ interface section of the m source file. In this case, this attribute is read-only externally and read/write internally ).
Third, you can declare the variables and attributes in this part. However, the declared variables, attributes, and methods are private and can only be accessed by the current class, which is equivalent to private.

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.