1

Working on an old objective c application where in I need to create multiple targets. Question is how do I differentiate between multiple targets run time in the code and accordingly I need to load the resources from bundle.

Dhaval H. Nena
  • 3,992
  • 1
  • 37
  • 50

2 Answers2

1

Project > Build Settings > Preprocessor Macros

define there different macros for different targets e.g.:

  • TARGET_1
  • TARGET_2

and in code you can diferenciate it like this:

NSString *pathToMyResource = nil;

#ifdef TARGET_1
  pathToMyResource = @"pathToMyResourceForTarget1";
#else
  pathToMyResource = @"pathToMyResourceForTarget2";
#endif

EDIT: added swift syntax

#if DEBUG
  let apiKey = "KEY_A"
#else
  let apiKey = "KEY_B"
#endif

see here: Swift 3: how to use PREPROCESSOR Flags (like `#if DEBUG`) to implement API keys?

Community
  • 1
  • 1
Vojta
  • 810
  • 10
  • 16
1

You can use @matloob's answer. Below is an another approach.

You can also use Preprocessing for differentiating among targets.

Please have a look at following tutorial. This may also help you.

Reference : Target Differentiation dynamically - Appcoda

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22