How can I access a user-defined Xcode build setting?

Viewed 48023

If I added a user-defined setting in my build configuration, how can I read that setting in my Objective-C code?

I have two files in my project, debug.plist and release.plist. I want my MainApp.m file to read one of these files based on which build configuration is running. I set up a user-defined setting named "filename" in both the Debug and Release configurations to point to the appropriate file. But I don't know how my MainApp.m file can read the filename variable from the current running configuration.

6 Answers

Swift 4

Lets say "filename" is the String you need in your app.

Add filename=YOUR_STRING to user-defined setting(for debug and release).

And add filename = $(filename) to info.plist.

Then in Swift code:

if let filename = Bundle.main.infoDictionary?["filename"] as? String {
    // do stuff with filename
} 
else {
    // filename wasn't able to be casted to String
}
Related