iPhone编译依赖于目标

hol*_*hol 3 iphone xcode objective-c target

我有多个目标的项目有多个客户端但是大多数应用程序是非常相同的,到目前为止,我能够控制不同的程序流与运行时读取的属性列表.

一个客户有一个特定的视图,我需要先显示所有其他人.

我的问题是我遇到了构建错误(实际上是链接错误),因为控制器类不在其他客户端目标中,我也不想包含它.所以我一直在寻找一些编译时控件.

我正在寻找类似的东西

#ifdef client1target
     ... do something
#else
     ... do something else
#endif    
Run Code Online (Sandbox Code Playgroud)

我遇到麻烦的程序部分就是这样看的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    NSString *client = [myEnvVariables getShortName]; // In this class method I read the plist

    if ([client isEqualToString:@"CLIENT1"]) {

        Client1SpecificController *mm = [[Client1SpecificController alloc] initWithNibName:@"Client1SpecificView" bundle:nil];
// here happens the compile error because Client1SpecificController is not known at other targets

        mm.view.frame = CGRectMake(0,20,320,460);

        [window addSubview:mm.view];
        [window makeKeyAndVisible]; 

    } else {

        [window addSubview:navigationController.view];
        [window makeKeyAndVisible]; 
    }

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

错误看起来像这样

undefined symbols:
  "_OBJC_CLASS_$_Client1SpecificController", referenced from:
      objc-class-ref-to-Client1SpecificController in myAppDelegate.o
Run Code Online (Sandbox Code Playgroud)

小智 9

打开一个目标的设置,然后转到"预处理器宏",设置你喜欢的任何东西 CLIENT_ONE

然后你可以在你的代码中使用它,如上所述

#ifdef CLIENT_ONE
    #import "ClassOneController.h"
#else
    #import "OtherController.h"
#endif
Run Code Online (Sandbox Code Playgroud)

以下是目标的构建设置的屏幕截图: 对于此示例,请添加CLIENT_ONE = 1