Summary of IOS Declaration property Keywords

Source: Internet
Author: User

Atomic:

Atomic operations (Atomicity refers to a complete operation of a transaction, the operation is committed successfully, and the reverse is rolled back.) Atomic operations are atomic operations) in the Objective-c property setting, the default is atomic , meaning that the Setter/getter function is an atomic operation, if the multi-threaded call setter at the same time, One thread does not appear until all of the setter statements have been executed, and the other thread starts executing the setter, which is equivalent to the function's tail and end lock. In this way, concurrent access performance will be low .

Nonatomic:

Non-atomic operations generally do not require multi-threading support when it is used, so that when the concurrent access to the efficiency is relatively high . In Objective-c, it is common for object types to be declared non-atomic. The system will only automatically generate a single main thread when the program is launched in iOS. When the program is executed, it is usually done in the same line thread face an attribute. If we determine that a property will be used in multiple threads in a program and need to do data synchronization, it must be set to atomic, But it can also be set to non-atomic, and then in the program with locks and the like to do data synchronization.

When declaring attributes in a header file, using atomic and nonatomic is equivalent to adding 2 functions to the header file, one for setting this property, and one for reading this property, for example:-(NSString *) name; -(void) SetName: (NSString *) str;

Atomic/nonatomic need and @synthesize/@dynamic match and use make sense.

@synthesize

If the setter and getter methods are not implemented, the compiler will automatically be in the production setter and getter method.

@dynamic

The property accessor method that represents the variable is implemented dynamically, and you need to inherit from the NSObject (BOOL) Resolveinstancemethod: (SEL) The method or function that specifies the dynamic implementation in the SEL method.

property to decorate other keywords:

Getter=gettername

specify the Get method, and you need to implement this method . You must return the same variable as the declared type, without parameters

Setter=settername

Specifies the set method and needs to implement this method . With a parameter that is the same as the declaration type, no return value (null value returned)

The set method cannot be specified when declared as ReadOnly

ReadWrite

If it is not declared as ReadOnly, then the default is ReadWrite . Can be used to assign values or to be assigned

ReadOnly

Can not be assigned a value

Assign

All properties are default assign , usually for scalar (simple variable int, float, cgrect, etc.)

A typical case is when the object is not owned, usually delegate, to avoid causing a dead loop (if the retain word will die)

Retain

The OBJC property must be an object that has ownership of the object and must be release once in the Dealloc.

Copy

The OBJC property must be an object that has ownership of the object and must be release once in the Dealloc. And the attribute must implement the Nscopying protocol

Generally used in NSString types

Summary of IOS Declaration property Keywords

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.