Objective C method syntax clarification
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:
开发者_C百科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
?
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];
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.
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.
精彩评论