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

Functions versus methods

The slide at the end of the Syntax Overview lesson provides the following breakdown of the Objective-C function-call syntax:

type foo = [classinstance instanceMethodwithParam1:param1 andParam2:param2];

which I think alludes to the second function call in main.m ([ball setRadius:25];):

int main()
{
    Sphere *ball = [[Sphere alloc] init];

    [ball setRadius:25];

    NSLog(@"ball radius %f", [ball radius]);

    return 0;
}

So how does andParam2:param2]; figure into this code? Or does it not refer to the example from the lesson?

2 Answers

The method setRadius: has only one argument. The method declaration should be something like this

- (void)setRadius:(int)radius;

The second parameter shown as example in the function call syntax just don't refer to setRadius: example.

Regards.

I think I know what you're saying, Emanuele, but why would the example in the slide include a function call that comprises two parameters? This would appear to go beyond the scope of the lesson.

I've come across something similar in the quiz following the @properties lesson. The question was:

Following is a valid statement to call a method:

[object methodName: paramName];

True or false.

But in the lesson, the method was called like this: [ball setRadius: 25]; Instead of 'paramName', a value is initialized.

Does anybody know what's going on?