Skip to content

Instantly share code, notes, and snippets.

@allanalves
Last active May 27, 2017 20:18
Show Gist options
  • Save allanalves/1a310899f9862a8eef46c82423bcd221 to your computer and use it in GitHub Desktop.
Save allanalves/1a310899f9862a8eef46c82423bcd221 to your computer and use it in GitHub Desktop.
enum Environment: String {
case production
case homologation
case development
case custom
}
static func preferredEnvironment() -> Environment {
if let env = UserDefaults.standard.string(forKey: "environment") {
return Environment(rawValue: env)!
}
return Environment.production
}
static func enviromentUrl(_ environment: Environment) -> URL? {
if let path = Bundle.main.url(forResource: "Service", withExtension: "plist"),
let data = try? Data(contentsOf: path) {
if let result = try! PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String:String] {
return URL(string: result[environment.rawValue]!)
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment