I made a custom Static Library 开发者_运维技巧that I use in an iOS project. When I use an NSKeyedUnarchiver to unarchive data. It throws an exception when I try to use it in the library. I tried copying the classes of my static library into my project to see if that would work and that resolves the issue, but obviously defeats the purpose of a static library. I also tried several combinations of release/debug and simulator/device and still does not work.
Is the NSKeyedUnarchiver having trouble finding the classes it needs to unarchive?
EDIT I tracked down the exception thrown and it says it is can't unarchive the class JGObjectRep which is one of the other classes in the static library. Keep in mind this works just fine if I copy these into the project.
Try adding these options to your Linker Flags: -ObjC -all_load
Sorry, I do not know the particularities of static libs used here, but here are some other thoughts I remember from other platforms.
First of all, the problem appears to be that the class information isn't fully available to the runtime system, hence the error.
Ergo, the static lib either doesn't include the needed information or the linker doesn't pass the information on. In the latter case, you're toast unless you can find extra linker options that enable such a feature. Hence, read the linker manual to see if there are related options.
In the former case, you could first look at the exported symbols with a tool (I believe "nm" can do this) to verify that the class name and its structure desciption is part of the symbols in the lib. I don't know how it has to look like, but maybe Google helps.
Another thought: Is that particular class being referenced by the main code? If not, the linker might not include it in the final code because it figures it's only used inside the static lib's environment and is thus not needed elsewhere. Hence, try to see if declarations either in the compiler's or linker's command options, or pragmas in source code, allow you to make this class globally known.
Good luck!
精彩评论