Use @ property in objective-C [5]

Source: Internet
Author: User

Introduction
Objective-C language keyword, paired with @ synthesize.
Function: Let the compiler automatically write a method declaration with the same name as the data member to save the declaration of the read/write method.
For example:
1. In the header file:

IOS code  
  1. @ Property int variable;

It is equivalent to declaring two methods in the header file:

IOS code  
  1. -(INT) variable;
  2. -(Void) setvariablet :( INT) newvariable;

2. Implementation file (. m)

IOS code  
  1. @ Synthesize variable;

It is equivalent to implementing two methods in the implementation file (. m.

IOS code  
  1. -(INT) Variable
  2. {
  3. Return variable;
  4. }
  5. -(Void) setvariable :( INT) newvariable
  6. {
  7. Variable = newvariable;
  8. }

The above equivalent functions are automatically filled by the compiler to help developers, simplifying the coding input workload.
Edit this section
Format

The syntax for declaring property is:
@ Property (parameter 1, parameter 2) type name;
For example:
@ Property (nonatomic, retain) variable * variable;
There are three types of parameters:
Read/write attributes: (readwrite/readonly)
Setter semantics: (assign/retain/copy)
Atomicity: (Atomicity/nonatomic)
Each parameter has the following meanings:
Readwrite
Generate the setter \ getter Method
Readonly
Only generate simple getter without setter.
Assign
Default type. The setter method directly assigns values without retain operations.
Retain
The setter method performs the release old value on the parameter, and then retain the new value.
Copy
The setter method performs the copy operation, which is the same as the retain method.
Nonatomic
Multithreading and Variable Protection are prohibited to improve performance.

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.