0

I have a project with many different schemes. Is there a way to check if I'm building a "module scheme" or an "app scheme", without editing my build settings? Something like:

#ifdef SOME_SPECIFIC_APP_MACRO

Thanks for your help.

0xChqrles
  • 433
  • 1
  • 5
  • 10
  • see this for help : [How do I get the name of the target that is currently running in Xcode?](https://stackoverflow.com/questions/36758639/how-do-i-get-the-name-of-the-target-that-is-currently-running-in-xcode/43306458) – Anbu.Karthik Jun 15 '20 at 08:11
  • That's interesting but I really need a conditional compilation. – 0xChqrles Jun 15 '20 at 08:20
  • Which way you prefer more? using pch files or build settings or configuration files? – Cy-4AH Jun 16 '20 at 19:33

2 Answers2

0

Say you have the following schemes named Maintenance, Debug and Release.

Assuming you have them properly set up with custom flags in your app Build Settings > Active Compilation Conditions.

In Swift you would simply do a conditional check like so:

#if Maintenance
    // ...
#elseif Debug || Release
    // ...
#else
    // ...
#endif

So, you do need to add a flag for your scheme in the Build Settings before using a conditional check for that specific scheme in your code. If you just look for a way to check the target though, you could easily grab that info from the plist I guess.

0

I don't know, may be Xcode have such defines already, but you can use this:

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) MACH_O_TYPE=BIN_TYPE_${MACH_O_TYPE} BIN_TYPE_mh_execute=1 BIN_TYPE_mh_bundle=2 BIN_TYPE_mh_object=3 BIN_TYPE_mh_dylib=4 BIN_TYPE_staticlib=5 IS_APP=MACH_O_TYPE==BIN_TYPE_mh_execute IS_NOT_APP=MACH_O_TYPE!=BIN_TYPE_mh_execute

You can put it in project build settings, or put in xcconfig and attach to project configs.

Then you can use them in conditional compilation

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22