Objective-C 2.0 properties

Apple’s “The Objective-C 2.0 Programming Language” is the official document on Objective-C 2.0. So, it is expected to explain all the features of the Obj-C 2.0 and how to use it. However, there is one thing missing in the document at least.

It is about how to use an variable of Objective-C object with different name of its property name.

What Apple’s document says is :

You can use the form property=ivar to indicate that a particular instance variable should be used for the property, for example:

@synthesize firstName, lastName, age = yearsOld;

This specifies that the accessor methods for firstName, lastName, and age should be synthesized and that the property age is represented by the instance variable yearsOld.
However, if you synthesize the “age” property like it, you are telling its compiler to write a setter and a getter method to use yearsOld variable for age property at “definition” time. Is this only way to do so?

Clues to Object-C 2.0” mentions this.

@property( ivar = yearsOld) int age;

You are telling the compiler to use yearsOld at “declaration” time.

If you want to know more about properties of Objective-C 2.0, there are other good documents on Obj-C 2.0 properties.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: