Objective-c @property & @synthesize Use

Source: Internet
Author: User

@property Declaration Properties
The way to specify attributes (attributes) For instance variables allows the compiler to generate leak-free and thread-safe ways to access instance variables.

@property is the corresponding compiler directive

Declares a property that has the same name as a data member to omit read and write functions
@interface     application { int versioncode;     int userId;      userinfo* UserInfo; Applicationinfo*applicationinfo;
}
@property (retain) UserInfo *userinfo;    @synthesize UserInfo;  @property (retain) applicationinfo* applicationinfo;       @synthesize ApplicationInfo; @end


The syntax for declaring a property is:
@property (parameter) type name;

The parameters here are divided into three main categories:

Read-Write properties: (readwrite/readonly)

Setter semantics: (assign/retain/copy)

Atomicity: (Atomicity (nonatomic)

Assign/retain/copy determines how to assign new values to data members
The default value for Atomicity is atomic, and the Read function is atomic.

The parameters that are often used are copy/reain/assign.

The setter in which to determine the property determines how to handle this property. Many of the objects in Objective-c are best used with retain, some special object (for example: string) using Copy.

The Assign keyword represents the setter's direct assignment, rather than copying or preserving it. This mechanism works well for some basic types, such as Nsinteger and cgfloat, or types that you do not directly own, such as delegates.

The ReadOnly keyword means that the setter will not be generated, so it cannot be used in combination with copy/retain/assign.

In the implementation, you only need to

@synthesize MainView;

@synthesize window;

Can replace the cumbersome setter, getter method, so that the compiler can automatically generate read and write functions, define the property, the user, you can click the number (.) To access the attribute.

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.