在 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 .
https://stackoverflow.com/questions/2097294/
相关文章:
objective-c - 解决 Objective-C 命名空间冲突的最佳方法是什么?
ios - 错误消息 '_BSMachError: (os/kern) invalid capabi
objective-c - Objective-C Cocoa 应用程序中的正则表达式
objective-c - 如何在 Objective-C 中传递多个参数?
ios - 以编程方式创建 UICollectionView
objective-c - UITextField 的初始键盘动画的超慢滞后/延迟