objective-c - Objective-C中方法旁边的加号和减号是什么意思?

标签 objective-c syntax method-declaration

在 Objective-C 中,我想知道方法定义旁边的 +- 符号是什么意思。

- (void)loadPluginsAtPath:(NSString*)pluginPath errors:(NSArray **)errors;

最佳答案

+ 用于类方法,- 用于实例方法。

例如

// Not actually Apple's code.
@interface NSArray : NSObject {
}
+ (NSArray *)array;
- (id)objectAtIndex:(NSUInteger)index;
@end

// somewhere else:

id myArray = [NSArray array];         // see how the message is sent to NSArray?
id obj = [myArray objectAtIndex:4];   // here the message is sent to myArray

// Btw, in production code one uses "NSArray *myArray" instead of only "id".

another question dealing with the difference between class and instance methods .

关于objective-c - Objective-C中方法旁边的加号和减号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2097294/

相关文章:

iphone - 为什么我的 ASIHTTPRequest 文件显示 ARC 错误?

c++ - const T* 与 typedef

c# - MethodBase.GetCurrentMethod()反射线解释

c# - 方法声明末尾的 new() 关键字

exception - 现有方法的消息无法理解

objective-c - 使用 __attribute__((nonnull(2))) 声明方法

objective-c - NSJSONSerialization解析特殊字符

iphone - UITableView 是否可以调整大小?我可以分配不同的框架吗?

objective-c - 即使在 alloc/init 之后,我的 NSMutableArray 也会在函数范围之外丢失它的对象

java - 在 clojure 中重复 "Have a nice day"用户请求的次数