Objective-C类别表现 [英] Objective-C Category Performance

查看:131
本文介绍了Objective-C类别表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用类别将我的Objective-C类的实现分解成多个 @implementation 块,那么会使得我的iOS应用程序的最终二进制文件变大或影响表现如何?

If I used categories to break up the implementation of my Objective-C class into multiple @implementation blocks, would that make the resulting binary of my iOS app larger or affect performance at all?

显然,您无法获取有关类别的详细信息运行时的类?所以,不应该将所得到的二进制文件与或不同类别相同,假设其他所有的相等?

Apparently, you can't Obtain details of categories on a class at runtime?. So, shouldn't the resulting binary be identical with or without categories, assuming all else equal?

我有一个 UIViewController 的自定义子类变得相当复杂。

I have a custom subclass of UIViewController that's getting rather complex.


iOS开发人员库:使用Objective-C进行编程:类别

除了向现有类添加方法之外,还可以使用类别来分割实现的复杂类跨越多个源代码文件。例如,如果几何计算,颜色和渐变等特别复杂,您可能会将自定义用户界面元素的绘图代码放在单独的文件中,以实现其余部分。

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 s相比)就是Xcode您的代码折叠整个 @implementation 块(但不是两个 #pragma标记之间的代码)。如果要将类别(可选地折叠)保留在与主类相同的文件中,这很有用。

The other nice thing about categories (as compared to #pragma marks, for example) is that Xcode lets you code fold an entire @implementation block (but not the code between two #pragma mark's). This is useful if you want to keep categories (optionally folded) in the same file as the main class.

推荐答案

链接器合并类和类别。如果您的类及其类别在构建时都链接到相同的可执行文件中,则成本为零。

The linker merges classes and categories when possible. If your class and its categories are all linked into the same executable at build time then the cost is zero.

这篇关于Objective-C类别表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆