Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Setter and Getter returning multiple values

I understand how to set up a setter and getter and return a value like so

// Used to set value in the function
-(void)setAge:(float)myAge;

// Would be used to get value
-(float)myAge;

But when dealing with multiple parameters like

-(void)setAge:(float)myAge setHeight:(float)height;

How would i use setters to set these functions in one line

1 Answer

Stone Preston
Stone Preston
42,016 Points

if you really wanted to do it in one line you could do

-(void)setAge:(float)myAge setHeight:(float)height {

    _myAge = myAge; _height = height;

}

you are going to have to use separate statements though no matter what

Ohh so i would have to do it separately referring to the one above so i would have to do this for the getters

-(float)myAge;
-(float)myHeight;
Stone Preston
Stone Preston
42,016 Points

yes you would need to use separate getters