Objective c 类别和继承的区别和用途是什么?

Objective c 类别和继承的区别和用途是什么?,objective-c,inheritance,objective-c-category,Objective C,Inheritance,Objective C Category,可能重复: 什么时候应该使用子类化,什么时候应该使用类别?当您想要扩展基础所使用的功能时,应该使用子类化 @interface MyObject: NSObject<SomeProtocol> @interface UIView (MyViewAdditions) - (void)recursiveEnumerateSubviewsUsingBlock:(void (^)(UIView *view, BOOL *stop))block;

可能重复:


什么时候应该使用子类化,什么时候应该使用类别?

当您想要扩展基础所使用的功能时,应该使用子类化

@interface MyObject: NSObject<SomeProtocol>
@interface UIView (MyViewAdditions)

- (void)recursiveEnumerateSubviewsUsingBlock:(void (^)(UIView *view, BOOL *stop))block;