The 11th chapter of "Objective-c Basic Course" Property __objective-c

Source: Internet
Author: User
11.1 Using attribute values (@property) 11.1.2 simplifies implementation code

@synthesize is a new compiler feature that represents the access code that created the property. When @synthesize rainhandling is encountered, the compiler speaks of adding-setrainhandling: And the-rainhandling Method's precompiled code (in later versions of Xcode4.5, you can not use @synthesize) 11.1. The magical uses of 3-point expressions

Point expression (.) Can make it easier to access the properties of an object
Point expression (.) Appears to the left of the equal sign, calling the setter method, for example

[Tire setrainhandling:20+i];

Equivalent to


If it appears to the right of the equal sign, the Getter Method 11.2 Property extension that calls the variable

@property, use
1, nonatomic if not used in multiple threads, you can increase access to the call speed, often used in iOS
2, do not want to retain a variable object, using assign (such as tick)
3. Copy Properties
4, weak will not make the super class of the reserved counter value plus 1,strong will 11.2.1 name use

The name of a property is always very common when the name of the instance variable that supports the property is the same. 11.2.2 Read-only properties

Make an object read-only, this property may be an immediate computed value, or it may be a different object that can only read values that cannot be changed.

@property (readwrite,copy) NSString *name;//can be read or modified
@property (readonly) nsstring read-only, Only claims getter without generating setter
Sometimes it's better to 11.2.3 yourself .

1, using @dynamic to the high-speed compiler do not claim any code goods create an instance variable of a response
2, the default claimed method name is blah: and Setblah: Format, if you want to replace, you can use getter= and setter= customization, such as

@property (Getter=isblah) Bool Blan;
11.2.4 characteristics are not omnipotent

Property only supports blah: and Setblah: Methods, but does not support methods that need to accept additional parameters 11.3 Summary

1. Declaration of automatically generating setter and getter methods using @property
2, using @synthesize and compiler instructions can inform the compiler to generate access methods (Xcode4.2 can not be used after)
3. @dynamic instruction The high speed compiler does not generate variables and code
4. Point expression: On the left side of the equal sign, setter; right, getter

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: 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.