Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether iOS app is running Debug or Release build without preprocessor macros, for unit testing purposes?

Tags:

xcode

ios

macros

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?

like image 586
Luke Avatar asked Nov 24 '25 08:11

Luke


1 Answers

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.

like image 118
Vishnu gondlekar Avatar answered Nov 27 '25 00:11

Vishnu gondlekar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!