Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: Objective-c 中继承和类别的区别
什么时候应该使用子类化,什么时候应该使用类别?
当您想要扩展基础使用的功能时,子类化。
@interface MyObject: NSObject<SomeProtocol>
当您想为您可能无法控制的代码添加便捷方法时,请添加一个类别。
@interface UIView (MyViewAdditions) - (void)recursiveEnumerateSubviewsUsingBlock:(void (^)(UIView *view, BOOL *stop))block;