> On 22 Feb 2015, at 06:03, Erwin Namal <[email protected]> wrote:
>
> Dear All,
>
> I am currently moving some of my app’s code out in a static library. I have
> subclasses of NSViewController and their nib.
> Searching on the net I fond a way to deal with the nibs, by adding a bundle
> target in the library for all the .xib files and importing the bundle as a
> resource in my app.
> Then, I can open the bundle and load the nibs.
>
> Now, when I do that, I get the following error in the console :
>
>> Unknown class ‘MyCustomView', using 'NSView' instead. Encountered in
>> Interface Builder file at path . . . .
>
> How can I fix it ?
>
> Thanks for your help
> – E
The problem with static libraries and xibs is that the linker doesn’t know
about the classes of objects in the xib so, if the class isn’t also referenced
in your source code somewhere, it doesn’t get linked in and so the nib loading
code can’t find it. This is a similar problem to using categories in static
libraries.
The constantly-recommended ‘solution’ for this is to pass the -ObjC or
-all_load flags to the link. I hate that solution because it causes most or all
of the static library to be linked into the code, whether you need it or not.
Due to various bugs in the linker in times past there’s a trail of advice to be
found suggesting you specify both flags and people have been gaily making huge
fat binaries ever since.
What I do in this case is ensure I have one source file (I usually call it
LINKERHACK.m) which has something like this in it
@interface LINKERHACK : NSObject
+(void)loadClasses;
@end
@implementation LINKERHACK
+(void)loadClasses
{
Class __unused class1 = [ SomeStaticClass class ];
}
@end
That’s enough to get the linker to pull in the class you want. I add classes
only found in the XIB into that list. I don’t believe you even need to call the
function anywhere, just compiling it in is enough to get the dependencies the
linker needs. Ugly, crude, but effective.
I filed an enhancement request years ago that NIBs should be processed and
added to the link-time required symbols. I have lost hope of ever seeing that
happen.
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]