Reputation: 41
I'm developing an iOS object serialization framework. The framework is capable of serializing objects of classes from various other frameworks (e.g. CLLocation from CoreLocation), so I've imported those frameworks in order to compile my code.
However, I don't want to require my clients to have to edit their XCode projects to "Link Binary With Libraries" for each of the frameworks that my framework serializes. Instead, I'd like the client to be able to exclude the frameworks he doesn't use (e.g. CoreLocation) from his project and still be able to build his project with my serialization framework.
I've configured the project for my framework such that CoreLocation is Optional, but the client still gets linker errors ("Undefined symbols for architecture i386:").
What am I missing? Are there alternative ways to achieve my desired behavior?
Upvotes: 2
Views: 801
Reputation: 41
I'm still not sure why it wasn't working, but I found a workaround for the location errors, so I thought I'd share that.
The 2 errors were:
(null): "_CLLocationCoordinate2DMake", referenced from:
...
(null): "_OBJC_CLASS_$_CLLocation", referenced from:
...
(null): Symbol(s) not found for architecture i386
By selectively commenting out lines of code from my file, I found the 2 main causes were
To fix #1, I just built the struct manually.
To fix #2, I abstracted all CLLocation class methods to use NSClassFromString. For example:
[CLLocation class]
becomes
[NSClassFromString(@"CLLocation") class]
The fix for #2 seems hacky, but just wrapping the original code with a conditional did not seem to fix the issue. Interestingly, I can still reference the CLLocation type like so:
CLLocation *loc = ((CLLocation *)obj);
I just can't seem to invoke any class methods without first using NSClassFromString.
Any insight to why I'm seeing this behavior would be appreciated, but for now, I can move on.
Upvotes: 2