2

I will try to explain my problem.

I am creating two libs home.a & room.a independently. From home lib I have calls to the functions which I implemented in room.a

I am want two use this two libs in one project, the case is I want to keep room.a as optional. If I don't add room.a in project, I am not able to build project.

Error is:

Undefined symbols for architecture
  "_RoomViewController", referenced from:
  -[ParentViewController openView:] in home.a

Here RoomViewController is class from room.a & ParentViewController is class from home.a

I want to add condition in code home.a to check RoomViewController is present then create a object of RoomViewController.

Please suggest me a way for to do this. Thanks in advance.

OnkarK
  • 3,745
  • 2
  • 26
  • 33
  • 1
    I doubt you can make static libs optionals as their objects are linked during compilation. However I'd look into iOS Frameworks, which are dynamic libs in disguise. Then with some `dlopen`/`dlsym` magic, you may possibly do what you're asking (disclaimer: I never actually tested this; just a though). – Guillaume Algis Jan 22 '15 at 13:50

1 Answers1

1

If you want the project to compile without errors, you need to add a header file that declares the RoomViewController class. For instance, write a RoomViewController+Private.h file.

@interface RoomViewController: UIViewController
@end
@interface RoomViewController()
//List of methods you want to use
- (void)methodA;
- (void)methodB;
@end

To check whether you linked the library room.a at runtime, you need to do the following:

if ([RoomViewController class]) {
    // class exists
    RoomViewController *instance = [[RoomViewController alloc] init];
} else {
    // class doesn't exist
}
riven
  • 73
  • 9