1

I have some code that sets some "developer only" settings when loading my app. I want to be able to have these settings turn on automatically only when my app is run for development (whether that's via Xcode, Simulator, in debug-mode, on a development device, etc).

What is the proper way to set this up so my "developer only" settings don't get accidentally released and used in the real world within my app.

// FIX ME: **** ADMIN CODE ****
// Turn off before uploading to production!

self.unlockCount = 10
self.unlockByItemCount = false
self.withIntro = false
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

1 Answers1

6

The proper way to do this is with a macro.

#if DEBUG
    self.unlockCount = 10
    self.unlockByItemCount = false
    self.withIntro = false
#endif
Liftoff
  • 24,717
  • 13
  • 66
  • 119
  • 1
    The second paragraph and code is wrong. The Active Compilation Conditions _already_ include `DEBUG`. – matt Jul 24 '18 at 21:28
  • AFAIK Those preproceessor macros aren't available in Swift – Alexander Jul 24 '18 at 21:54
  • @Alexander They are available, but it is called 'Additional Swift Flags`. In Xcode project, add '-D DEBUG' in 'Build Settings -> Additional Swift Flags' – CZ54 Jul 25 '18 at 08:00