Created
August 15, 2017 03:49
-
-
Save dmurawsky/dbfd9fc9d28cff729db61928cac892bf to your computer and use it in GitHub Desktop.
Parse ios.env in Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func DotEnv() { | |
guard let path = Bundle.main.path(forResource: "ios", ofType: "env") else { return } | |
let url = URL(fileURLWithPath: path) | |
do { | |
let data = try Data(contentsOf: url) | |
let str = String(data: data, encoding: .utf8) ?? "Empty File" | |
let clean = str.replacingOccurrences(of: "\"", with: "") | |
print(clean) | |
let envVars = clean.components(separatedBy:"\n") | |
for envVar in envVars { | |
var keyVal = envVar.components(separatedBy:"=") | |
if keyVal.count == 2 { | |
setenv(keyVal[0], keyVal[1], 1) | |
} | |
} | |
} | |
catch { print(error) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment