Thanks, Chris. I ended up with something similar: the optional lib2.a contains a factory class which creates a an object that implements a certain protocol that exposes the optional functionality. This is the header:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol OptionalStuffDelegate
// Delegate methods here
@end
@protocol OptionalStuff
// Methods here
@end
@interface OptionalStuffFactory : NSObject {}
+ (id<OptionalStuff>)instantiateWithDelegate:(id <OptionalStuffDelegate>)delegate baseView:(UIView *)baseView;
@end
To instantiate in lib1.a, I do:
Class optionalStuffFactoryClass = NSClassFromString(@"OptionalStuffFactory");
if (optionalStuffFactoryClass != nil)
{
optionalStuff = [optionalStuffFactoryClass performSelector: @selector(instantiateWithDelegate:baseView:) withObject: self withObject: glView];
}
lib2.a implements the factory class. The fact that there aren't any compile-time references to the OptionalStuffFactory class makes sure there are no unresolveds if lib2.a is missing.
Important: You have to make sure the build target that includes the library uses the linker flag -ObjC, otherwise the factory class will be optimized away since there are no compile-time references to it.