<分区>
<分区>
Possible Duplicate:
What do the plus and minus signs mean in Objective C next to a method?
我在类里面对 -(type) 和 +(type) 感到困惑。
@interface Class:Something{
+(id) foo;
-(void) fooAgain;
}
+(type) 是类级函数(根据谷歌) 但我不明白类级别功能的含义。 +(id)foo 内部是一种{返回一些值} 我认为它类似于 getter 或 setter 但不知何故它一定是不同的。 (因为@property 指的是 getter/setter)
谁能简单解释一下?谢谢
最佳答案
类方法 应该使用类名 本身来调用。并且,应该使用类的实例调用实例方法。
因此,您必须从其他一些类调用上述方法,如下所示,
类方法:
[Something foo]; // Correct
[Something fooAgain]; // Crash
实例方法:
Something *aThing = [[Something alloc] init];
[aThing fooAgain]; // Correct
[aThing foo]; // Crash
关于iphone - Objective-C:类级别函数的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518633/
相关文章:
objective-c - 如何使 UIWebView 在 Objective-C 中不可见
ios - Swift 正确声明对应于协议(protocol)并具有父类(super class)的对象
iOS Autolayout - 框架大小未在 viewDidLayoutSubviews 中设置
ios - 如何在 iOS 的多个 friend 墙上分享 google Plus 中的消息?
IOS-TableView Cell : dequeueReusableCellWithIdentifier issue