3

I'm new to Objective C and I'm going through a tutorial I found online. The tutorial starts to talk about messaging and argument separation and gives an example:

When there's more than one argument, they're declared within the method name after the colons. Arguments break the name apart in the declaration, just as in a message.

- (void)setWidth:(float)width: height:(float)height; 

I don't think there is suppose to be a colon after width, but I could be wrong. From what I've researched, I believe that it's a typo, but since I am new I just wanted to check.

Is the method just setWidth: height: ? Or is there another argument after the (float)width other than height:(float)height?

3 Answers 3

2

It's a typo. The method signature should read:

- (void)setWidth:(float)width height:(float)height;

The method name is setWidth:height: and you would call it like this:

[someObject setWidth:aFloat height:anotherFloat];

Sign up to request clarification or add additional context in comments.

Comments

1

You are correct. The middle colon seems to be a typo. After a colon, there should be a variable placeholder. If there's a space after a colon (as in this case) it's a typo.

Comments

0

Yep you would be correct. That is a typo. You would call that method like so:

[obj setWidth:100.0f height:200.0f]; 

Referencing that method in documentation or for a method callback it should be labeled setWidth:height: (note the trailing colon). Good luck with the rest of the tutorial.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.