Objective C 方法语法澄清
我是 Objective C 新手,正在学习我在网上找到的教程。本教程开始讨论消息传递和参数分离,并给出了一个示例:
当有多个参数时,它们在方法名称中的冒号后面声明。参数在声明中将名称分开,就像在消息中一样。
- (void)setWidth:(float)width: height:(float)height;
我认为宽度后面不应该有冒号,但我可能是错的。根据我的研究,我相信这是一个错字,但由于我是新人,我只是想检查一下。
该方法只是 setWidth: height:
吗?或者在 (float)width
之后除了 height:(float)height
之外还有其他参数吗?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个错字。方法签名应为:
- (void)setWidth:(float)width height:(float)height;
方法名称为
setWidth:height:
并且您可以调用它像这样:[someObject setWidth:aFloat height:anotherFloat];
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.
是的,你是对的。那是一个错字。您可以像这样调用该方法:
在文档中引用该方法或对于方法回调,应将其标记为 setWidth:height: (注意尾随冒号)。祝您学习本教程的其余部分一切顺利。
Yep you would be correct. That is a typo. You would call that method like so:
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.