在 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/