开发者

iOS: Conditional code depending on current target

开发者 https://www.devze.com 2023-04-05 16:15 出处:网络
I have two targets in my iPhone iOS project: Production and Preview. I now want to execute a line of code, only if I am in the target Preview.

I have two targets in my iPhone iOS project: Production and Preview.

I now want to execute a line of code, only if I am in the target Preview. I guess this would have to be some sort of #ifdef .... I found a solution which does almost the thing I want but it uses the configuration and not the target.

Example:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
开发者_如何学Go
  #ifdef MY_PREVIEW_TARGET
    [SomeLibraryWhichIsInPreviewTarget someMethod];
  #endif

  // Code that applies for both targets ...
}

Thanks for your help


Sams solution worked fine.

  1. Open The Preview's target's build settings
  2. Set the Preprocessor Macros to MY_PREVIEW_TARGET=YES and then I can use my code above to check for the target.


You could add a preprocessor ifdef in the Preprocessor Macros section of the build settings.

0

精彩评论

暂无评论...
验证码 换一张
取 消