Am having problems adding a user-defined setting

I wanted to have more than just        

Code Block
#if DEBUG
...
#endif


So in the project editor I added a user-defined setting

Wasn't sure exactly how to label and value, so I've tried

So I've tried it as (under user-defined)

MYSCENE MYSCENE
MYSCENE 1
MYSCENE DEBUG

And yet I can't get #if MYSCENE to work.

Any thoughts?
Answered by DTS Engineer in 648245022

This is what I want:
#if MYSCENE
print ("\(GameScene Complete)")
#endif

adding MYSCENES=1 to : GCCPREPROCESSORDEFINITIONS 
does not work

Right, this doesn't work because your print statement is in Swift, and GCC_PREPROCESSOR_DEFINITIONS only applies to C languages.

adding MYSCENES to SWIFTACTIVECOMPILATION_CONDITIONS 
does work, however I can only add one. when I add MYSCENES, it works. But if try to add another, it over writes the MYSCENES

When you modify this setting in Xcode, you should get a popover in the Build Settings table, and you can add multiple entries to this setting with the plus button.
In Objective-C, C, and C++ code, these pre-processor definitions are defined in GCC_PREPROCESSOR_DEFINITIONS. In Swift, they are compilation conditions, and defined by SWIFT_ACTIVE_COMPILATION_CONDITIONS.

In Swift, they are compilation conditions, and defined by SWIFTACTIVECOMPILATION_CONDITIONS.

Hope you don't mind, but while it works, I still want to make sure I put it where I should.

Project -> Build Settings -> All > (search) "Active Compilation"

select Active Compilation Conditions
click +
select Add Conditional Setting
under Debug there is now this additional line :


Any Architecture | Any SDK _______________ MYSCENE_______________ MYSCENE

Again, does work, but it wouldn't be my first time get the result I want but doing it incorrectly

p.s. I can only add one. I try to add a second one, and it overwrites the first. Can't see how to insert it.






You are confusing Xcode user-defined settings with preprocessor directives. Xcode user-defined settings can only be used inside Xcode itself. They are useful to define as placeholders inside your Xcode project, so you can build a representative debug version perhaps. Then, for your production builds, you use xcodebuild on the command line and specify platform-specific values for those user-defined settings.

Preprocessor defines are specified in build settings under "Other C flags". You would add something like -DMYSCENE.


Preprocessor defines are specified in build settings under "Other C flags". You would add something like -DMYSCENE.

Huh, there it doesn't work.
I found Other C Flags, selected DEBUG
clicked to ADD CONDITIONAL SETTING

and it didn't work from there.

To be safe I tried it with and without the -D
I even used cut and paste so there would be no typo errors

I know Xcode has been under quite a few changes, am using version 12.1 (in was that makes a difference)


it doesn't work. 

Can you clarify what you are expecting to happen? A basic test would be something like:

Code Block
#if MYSCENE
#error It's working!
#endif

I was originally just kinda guessing what you were talking about because you were mentioning user-defined settings. It looks like you may be still trying to combine my advice about preprocessing defines with edford's advice about Xcode-settings. Both are valid, but not necessarily at the same time. They are two different things.


Another way of understanding the problem here is to use the built-in DEBUG value as an example.

Create a new Xcode project with an app target, and look in the build settings for DEBUG. You will see two definitions, one for C-based apps in GCC_PREPROCESSOR_DEFINITIONS as DEBUG=1 and other in SWIFT_ACTIVE_COMPILATION_CONDITIONS as just DEBUG for Swift apps. Add MYSETTING to both of those to experiment.
This is what I want:

#if MYSCENE
print ("\(GameScene Complete)")
#endif

It does work with #DEBUG, like you said it's built in

adding MYSCENES=1 to : GCCPREPROCESSORDEFINITIONS
does not work

adding MYSCENES to SWIFTACTIVECOMPILATION_CONDITIONS
does work, however I can only add one. when I add MYSCENES, it works. But if try to add another, it over writes the MYSCENES


Accepted Answer

This is what I want:
#if MYSCENE
print ("\(GameScene Complete)")
#endif

adding MYSCENES=1 to : GCCPREPROCESSORDEFINITIONS 
does not work

Right, this doesn't work because your print statement is in Swift, and GCC_PREPROCESSOR_DEFINITIONS only applies to C languages.

adding MYSCENES to SWIFTACTIVECOMPILATION_CONDITIONS 
does work, however I can only add one. when I add MYSCENES, it works. But if try to add another, it over writes the MYSCENES

When you modify this setting in Xcode, you should get a popover in the Build Settings table, and you can add multiple entries to this setting with the plus button.
I got it to work, found the popup window, and have experimented multiple DEFINES

Please let me know I have it right if you can

www. warptv.com/links/screen1.png
Yes, you screenshot at that URL looks right.
Am having problems adding a user-defined setting
 
 
Q