Reputation: 9700
I've seen plenty of answers and am familiar with using something preprocessor macros to check whether I'm in debug or release mode, but I'm keen to unit test around those scenarios, so I'd love a way to check that that I could mock.
Can we detect debug, ad hoc or release without using an #if defined
?
Upvotes: 3
Views: 887
Reputation: 3956
You can have a key configuration
in info.plist with value ${CONFIGURATION}
. Make sure path for your plist file is set in you project build settings. See images below for reference.
You can then access infoDictionary to get the configuration. Code is below
let bundle : NSBundle = NSBundle.mainBundle()
let configuration : String = (bundle.infoDictionary!["configuration"] as! String) // configuration is key you set in plist file
configuration
will be a string storing build configuration set in your scheme.
Upvotes: 3