类方法和实例方法说明
到目前为止,我想知道这两者之间的区别。我一直在使用实例方法,但不知道其背后的含义。谁能用最简单的方式解释一下?谢谢。
Until now, I would like to know the difference between these 2. I always been using instance methods but have no idea the meaning behind it. Can anyone explain in the simplest way? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类方法在类本身上调用,如下所示:
在实际对象上调用实例方法:
阅读 Objective-C 编程语言指南更多信息。
Class methods are called on the classes themselves, like this:
Instance methods are called on actual objects:
Read the The Objective-C Programming Language guide for more information.
可以在不创建类实例的情况下使用类方法。
由于您没有此类的实例,因此您无法使用任何类实例变量。
例如:
因此您可以这样调用:
但是您不能使用属性
latChecked
因为这需要MyStringHelper
类的实例。Well class methods can be used without making an instance of a class.
Since you don't have an instance of this class you can't use any class instance variables.
ex:
Thus you can call this like:
But you can't use the properties
latChecked
because this will need an instance of theMyStringHelper
class.