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.
            Asked
            
        
        
            Active
            
        
            Viewed 1,095 times
        
    1
            
            
        - 
                    By using bundle Identifer - if you use different bundle identifiers for both targets. – Krunal May 09 '17 at 11:44
2 Answers
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?
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
 
     
    