这两种语法类型有什么区别? (目标-C)
我只是想了解这种类型的语法,
我知道例如
[instanceOfClass Method];
。 [myImage setImage:[NSImage imageNamed:@"picture.jpg"]];
对类的实例执行方法。
但这是如何工作的..
Variable = [Class methodName];
例如。 int Value = [sender intValue];
有人可以向我解释一下吗?我知道第一个示例对类、类或变量的实例执行一个方法。
但是后一部分是如何工作的呢?
非常感谢。
I'm just trying to get my head around this type of syntax
I know that the
[instanceOfClass Method];
eg. [myImage setImage:[NSImage imageNamed:@"picture.jpg"]];
performs a method on the instance of the class.
but how does this work..
Variable = [Class methodName];
eg. int Value = [sender intValue];
can someone explain this to me. I get that the first example performs a method on instance of class, class or variable..
but how does the latter part work?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有实例方法(使用
-
定义)和类方法(使用+
定义)。实例方法在实例中调用,类方法在类中调用。除此之外,你的例子:
似乎是一个实例方法。如果它在操作中,请记住
sender
只是一个参数:There are instance methods (defined with a
-
) and class methods (with a+
). Instance methods are called in instances and class methods in classes.Apart from this, you example:
Seems to be an instance method. If it's inside an action, keep in mind
sender
is just an argument:第二个示例还在类的实例上执行一个方法,但该方法返回一个分配给等式左侧的值的值。
我建议花一点时间阅读 Apple 提供的介绍。这个具体问题是 文档这部分讨论了:
The second example also performs a method on an instance of a class, but that method returns a value which is assigned to the value on the left side of the equation.
I'd recommend spending a little time reading the introduction provided by Apple. This specific question is discussed in this part of the document: