Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@property @synthesize

Tags:

iphone

What do @synthesize and @property do in Xcode? Please provide an explanation in really simple terms?

like image 801
Sam Jarman Avatar asked Jan 09 '10 08:01

Sam Jarman


2 Answers

You asked for simple terms:

@property declares a property in your class header

@property (nonatomic, retain) NSString *myString;

@synthesize creates your setter and getter for your property (accessor methods)

Without synthesize you have to write your own setter and getter implemention, like getMyString or setMyString (capitalize the first character of your property)

Sam: Just an advice: http://www.cocoadevcentral.com/d/learn_objectivec/ is a pretty solid resource to learn about basics like properties.

Good Luck!

like image 139
Henrik P. Hessel Avatar answered Sep 17 '22 17:09

Henrik P. Hessel


Properties and synthesized accessors are new features in Objective-C 2.0.

When you declare a @property you declare somewhat an instance var. Then you @synthesize accessor methods (i.e. getter and setter) for that property.

There are also @dynamic accessors if you're interested.

You should really do your homework on this. Apple has nifty pdf for that.

like image 38
Eimantas Avatar answered Sep 19 '22 17:09

Eimantas