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

时间:2012-11-12 12:53:42

标签: objective-c inheritance objective-c-category

  

可能重复:
  Difference between inheritance and Categories in Objective-c

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

1 个答案:

答案 0 :(得分:0)

当您想要扩展基础使用的功能时的子类。

@interface MyObject: NSObject<SomeProtocol>

如果要为可能无法控制的代码添加便捷方法,请添加类别。

@interface UIView (MyViewAdditions)

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