如果我使用类别将我的 Objective-C 类的实现分解为多个 @implementation
block ,这是否会使我的 iOS 应用程序生成的二进制文件更大或完全影响性能?
显然,你不能Obtain details of categories on a class at runtime? .那么,假设所有其他条件都相同,生成的二进制文件是否应该与类别或不类别相同?
背景
我有一个 UIViewController
的自定义子类,它变得相当复杂。
iOS Developer Library : Programming with Objective-C : Categories
As well as just adding methods to existing classes, you can also use categories to split the implementation of a complex class across multiple source code files. You might, for example, put the drawing code for a custom user interface element in a separate file to the rest of the implementation if the geometrical calculations, colors, and gradients, etc, are particularly complicated.
关于类别的另一个好处(例如,与 #pragma mark
相比)是 Xcode 允许您代码折叠整个 @implementation
block (但不是两个 #pragma mark
之间的代码)。如果您想将类别(可选择折叠)保留在与主类相同的文件中,这将很有用。
最佳答案
链接器尽可能合并类和类别。如果您的类及其类别在构建时都链接到同一个可执行文件中,那么成本为零。
关于Objective-C 类别性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19598557/