Search code examples
iosworkspace

iOS - 2 projects in a workspace and referencing the same files - how to determine which project I am in?


I currently have 2 projects in a workspace. The files are being referenced from Project A to Project B. My question is what is the cleanest way to determine which project I am in. For instance, I want to use ViewController1 (VC1) for both apps.

Thinking of this with a generic boolean. If I am in project A show this, else show this...


Solution

  • You might be able to do it with command line preprocessor definitions. If you can define _PROJECT_A_ on one, and _PROJECT_B_ on the other, you could do something like:

    #if defined(_PROJECT_A_)
        // do project A things
        static const BOOL ProjectBMode = NO;
    #elif defined(_PROJECT_B_)
        // do project B things
        static const BOOL ProjectBMode = YES;
    #endif
    

    Or use other #defines instead of a BOOL. See this thread.