+ [NSObject load] vs static library: 0-1 ?

Problem:


The + load implementation of a category of a Foundation class (NSData) is not called when the Category is part of a static library (.a).


If the code is moved to the project of the application that uses this library, + load is called. (So it's not a problem related to NSData apparently being a meta-class).


Based on the documentation, I would tend to believe that this should work also from a static library. Maybe something needs to be changed in the Static Library target settings in Xcode but so far I have not found something that resolves the issue.


Question:


Are the + load methods of categories called when the categories are defined in a static library? If they are, what could prevent this from happening?

Accepted Reply

I’m not sure is urls are allowed in the forums. You can do a Google search for “QA1490” from Apple for the solution.

Replies

I’m not sure is urls are allowed in the forums. You can do a Google search for “QA1490” from Apple for the solution.

Using -ObjC for the other linker settings on the main app (and not the static library as I tried to) solves the issue.

I’m not sure is urls are allowed in the forums.

FYI, URLs to specific domains, including

apple.com
, do not require moderation.

Also, for the benefit of folks reading along at home, here’s that link: QA1490 Building Objective-C static libraries with categories.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The

+load
implementation of a category of a Foundation class (
NSData
) …

What does this

+load
method do? I ask because, in general, adding
+load
methods in frown upon because it impacts on launch time. We generally recommend that you find an alternative approach. For example, if you’re using this to initialise some state that other methods in your category rely on, it’s better to do that initialisation lazily, using
dispatch_once
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"