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

在 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 应用程序中的正则表达式

ios - 有没有办法检查iOS应用程序是否在后台?

objective-c - 如何在 Objective-C 中传递多个参数?

ios - 如何以编程方式从类加载 Storyboard?

ios - 以编程方式创建 UICollectionView

objective-c - UITextField 的初始键盘动画的超慢滞后/延迟

ios - 为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩

objective-c - 将 UIImage 转换为 NSData