简体   繁体   中英

Difference between Xcode build settings and Scheme environment variables

What is the difference between setting environment variables in Build Stting>User Defined vs Edit Scheme>Arguments>Environment Variables? I have a Debug Staging Configuration and using it in a scheme. Would like to use these variables in info.plist and inside my Swift code. (setting URL endpoints, api keys etc.) to switch between environments.

Build Setting are used when building. The Scheme > Run > Arguments > Environment Variables are used at run time.

If you want to use variables in your .plist file, you'll need to have them available when building, so Build Settings is where you'll define them.

You can access the environment variables by:

Swift:

  let environment = ProcessInfo.processInfo.environment
    if let environmentValueString = environment["VARIABLE_NAME"] {
        environmentValue.text = environmentValueString
    }

Objective C:

    NSDictionary *environment = [[NSProcessInfo processInfo] environment];
    if (environment[@"server_url"]) {
// Set server url with the value in the         environment
    } else {
       // Set the default one
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM