-3
可能重复:
Difference between inheritance and Categories in Objective-c类别和继承有什么区别和使用?
什么时候应该使用子类时,我应该使用类别?
可能重复:
Difference between inheritance and Categories in Objective-c类别和继承有什么区别和使用?
什么时候应该使用子类时,我应该使用类别?
子类,当你想扩展基地使用的功能。
@interface MyObject: NSObject<SomeProtocol>
,当你想添加一个便捷方法的代码,你可能无法控制添加的类别。
@interface UIView (MyViewAdditions)
- (void)recursiveEnumerateSubviewsUsingBlock:(void (^)(UIView *view, BOOL *stop))block;