[Objective C] Property Study Notes

Source: Internet
Author: User

1. The @ public, @ private, and @ protected defined in the class only affect the access permission of the class that inherits it.

2. @ property automatically adds the getter/setter Method to the variable.

3. getter method:

1 -(id) name
2 {
3 return name;
4 }

4. setter method:

1-(void) setname :( ID) _ name
2 {
3 if (name! = _ Name)
4 {
5 [Name Release];
6 name = [_ name copy]; // when the copy parameter is set
7}
8}

5. @ property's copy, retain, and assign Parameters

Affected setter functions:

Copy: name = [_ name copy]; // nsstring recommended

Retain: Name = [_ name retain]; // other object types are recommended.

Assign: Name = _ name; // delegate, basic data type (INT) is recommended

6. @ readonly parameter of property

Generate only getter Functions

7. @ property's atomic, nonatomic Parameter

Atomic ensures the thread security of getter and setter to a certain extent, but it cannot be completely dependent.

Nonatomic does not guarantee thread security and speed. Nonatomic is used in most cases.

8. @ property default parameters:

Atomic, assign, readwrite

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.