IOS Basics of--properties

Source: Internet
Author: User

An introduction to the properties of @property methods in iOS programming is very concise and straightforward, and the original link is to be stamped.

= = = Read after split line = =

After iOS 5, with the advent of arc, there was no need for manual memory management, and there were some changes in the properties of the @property.

It is often used as follows:

Property function Introduction
Getter= Give Getter Method a custom name
Setter= Give setter method a custom name
ReadOnly Do not generate setter methods
Nonatomic Prohibit multi-threading, which improves performance compared to default thread protection (atomic)
Memory Management Properties
Weak Weak reference, the declared variable has no ownership of the object and prevents retain cycle
Strong Strong reference, the declared variable holds ownership of the object
Copy Create and reference a copy of an Assignment object

Copy property:

Can be used to override the strong property. It is best to declare variables (values) instead of connections or relationships.

In the Car.h:

@property (nonatomic, copy) NSString *model;

Car *honda =[[Car alloc] init]; Nsmutablestring*tmp = [nsmutablestring stringwithstring:@"Honda"]; Honda.model=tmp; NSLog (@"%@", Honda.model);//Honda[tmp setString:@ "Nissa"]; NSLog (@"%@", Honda.model);//Honda

When the variable property is copy, the change of the TMP value does not change the value of Honda.model, and the Honda.model value under the Strong\weak property changes.

Weak properties:

Delegate and outlet apply the weak attribute to declare.

Other Properties (deprecated in development after iOS 5):

Retain

unsafe_unretained

Assign

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.