我很难理解 Objective-J / Objective-C 中的方法签名
我很难理解 Objective-J 中的方法签名(但在 Objective-C 上应该是相同的)。
语法应该是:
-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
类型在括号之间指定。但是,我发现了以下代码行:
1)
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
为什么参数在括号之间传递?我以为你在冒号“:”之后指定参数。
2)
-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;
什么是“withSpecifiedPreferences”?是描述吗?它有什么用?
谢谢
I've some hard time to understand method signatures in Objective-J (but it should be the same on Objective-C).
The syntax should be:
-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
The type is specified between parenthesis. However, I've found the following code line:
1)
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
Why are the parameters passed in between parenthesis ? I thought you specify parameters after a colon ":".
2)
-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;
what's "withSpecifiedPreferences" ? Is it the description ? What's the use of it ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1) 显示了两种风格的混合,Objective-C 风格的方法调用:
和 C 风格的函数调用:
Objective-J 是 JavaScript 的严格超集,这意味着您可以使用除了 JavaScript 的 C 风格函数调用语法之外,还有消息传递语法。
在 2) 中,
withSpecifiedPreferences:
是方法(或“选择器”)名称的一部分,请参阅 "消息语法"。1) shows a mix of two styles, the Objective-C style method calls:
and C-style function calls:
Objective-J is a strict super-set of JavaScript, which means that you can use the message-passing syntax in addition to the C-style function call syntax JavaScript has.
In 2),
withSpecifiedPreferences:
is part of the methods (or "selectors") name, see "Message Syntax".因为
CGRectMake()
和CGRectGetHeight()
是 C 函数,而不是 Objective-C 或 Objective-J 方法。对于 C 函数调用,参数在括号中以逗号分隔进行传递。然后,
CGRectMake()
的结果作为参数传递给CPView
类的initWithFrame:
方法,该方法是一个 Objective -C方法。至于你的第二个问题,我以前没有见过该方法,所以我无法真正判断
prefs
参数的用途......Because
CGRectMake()
andCGRectGetHeight()
are C functions, not Objective-C or Objective-J methods. Parameters are passed comma-separated in parentheses for C function calls.The result of
CGRectMake()
is then passed as a parameter to theinitWithFrame:
method of theCPView
class, which is an Objective-C method.As for your second question I've not seen that method before so I can't really tell what the
prefs
parameter is used for...