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 Objective-C Basics (Retired) Introduction to Objective-C Syntax Overview

Chris Good
Chris Good
7,747 Points

In this, for the combined setter method, should it not be setCenter and setRadius vs. setCenter and radius?

I was just a little confused otherwise would imply something different about the syntax works. Thanks.

2 Answers

Stone Preston
Stone Preston
42,016 Points

setters for single properties take the form of

- (void)setPropertyName:(type)parameterName;

setter/getter methods for a property need to be named using specific conventions (propertyName for the getter, setPropertyName for the setters)

for multiple property setters, you separate the parameters in the method name. after each parameter you would add a space and then the next part of the method name with its parameter. generally you use set only for the first parameter. you could use set for each parameter, it wont make a difference.

- (void)setCenter:(float)center andRadius:(float)radius;

or you could do

- (void)setCenter:(float)center andSetRadius:(float)radius;

although the first one reads more clearly so I would use the first one

Chris Good
Chris Good
7,747 Points

Thanks! I think in the tutorial what had me a little confused was the second parameter is just "radius," so I was curious as to how you would call it cause technically it would be "setCenter: nil radius: nil" (for example) based upon the video right?

Stone Preston
Stone Preston
42,016 Points

yes you would call it like so (assuming you have allocated and initialized a shape object named myShape):

[myShape setCenter:5.0 radius:3.0];