Reputation: 13
Is it was possible to add objects/classes to a static library in a way that would let them be excluded when the library is weak linked? I tried adding attributes to my obj c classes that tag them as "weak_import" but the compiler says it is undefined.
Upvotes: 1
Views: 806
Reputation: 43452
Yes, it is possible. Unfortunately, while the runtime and linker support it, the compiler does not, which means you need to declare the assembly stubs for the classes in the headers. In particular, if you wanted to make MyClass weak you would do this in MyClass.h
:
asm(".weak_reference _OBJC_CLASS_$_MyClass");
asm(".weak_reference _OBJC_METACLASS_$_MyClass");
@interface MyClass
@end
This will only work on iOS 3.1 and later. For more details read this blog post.
Upvotes: 4