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;

Interactive developer, Author - iOS development with Swift - book coming 2017 https://manning.com/books/ios-development-with-swift

Tagged with:
Posted in Objective C

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: