3

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?

1 Answer 1

3

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.

plist image

info.plist link image

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great idea! Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.