Getters and Setters in Objective C

Doing a lot of Objective C lately, thought it worthwhile to write a few key differences with Actionscript. To begin with today – getters and setters!

Properties in Objective C are automatically given setters and getters eg:

@property (strong,nonatomic) NSString *name;

is automatically given:

the getter:

-(NSString *)name
	return _name;

the setter:

-(void)setName:(NSString *)name
	_name = name;

You can replace these in your code. If you replace both, you need to add the line:

@synthesize name = _name;

iOS development with Swift - book: video course:

Tagged with:
Posted in Objective C

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: