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;
我有一个关于在 shell 脚本中嵌入脚本文件的问题。我经常需要创建一个单独的 shell 脚本来解包其他脚本,但我真的不喜欢注释掉所有嵌入脚本的变量。我的 shell 脚本内容示例:
echo "Hello world" pwd cat>embedded_perl_script&l