Creating environment variables in Xcode 6.0 schema and obtaining them back from code in swift

99封情书 提交于 2019-12-22 04:05:06

问题


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?


回答1:


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
}


来源:https://stackoverflow.com/questions/27278303/creating-environment-variables-in-xcode-6-0-schema-and-obtaining-them-back-from

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!