Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C Category Performance

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?

Background

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

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.

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.

like image 962
ma11hew28 Avatar asked Dec 20 '22 22:12

ma11hew28


1 Answers

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.

like image 158
Greg Parker Avatar answered Jan 01 '23 02:01

Greg Parker