Creating environment variables in Xcode 6.0 schema

2019-04-21 20:59发布

How can I add some environment variables through a schema and then retrieve those variables using code?

For example I want to add an environment variable to describe the "exec_mode" like "development" or "production"... and I though to add this variable directly into the schema "environment variables". Now how can I get this variable back into my code in Swift?

标签: swift xcode6
1条回答
一夜七次
2楼-- · 2019-04-21 21:53

You can get the environment variables with NSProcessInfo:

let env = NSProcessInfo.processInfo().environment
if let mode = env["exec_mode"] as? String {
    print(mode)
} else {
    // Environment variable not set
}

Swift 3:

let env = ProcessInfo.processInfo.environment
if let mode = env["exec_mode"] {
    print(mode)
} else {
    // Environment variable not set
}
查看更多
登录 后发表回答