An easy to use interface for accessing environment variables with Swift
You can add this to your Package.swift
manifest with
.package(url: "https://github.com/eman6576/SwiftEnv.git", from: "1.1.0")
You can read in a value for a enviroment variable using either valueForEnviromentVariable
or the subscript for syntatic sugar.
let ENV = SwiftEnv()
// Optional("Users/<name of user directory>/")
// Gets value for key `PATH` using method
let path1 = ENV.valueForEnvironmentVariable("PATH")
// Optional("Users/<name of user directory>/")
// Gets value for key `PATH` using subscript
let path2 = ENV["PATH"]
You can set a value for an environment variable using either setValueForEnvironmentVariable
or the subscript for syntatic sugar.
let ENV = SwiftEnv()
// Set value for key `BUILD_CONFIGURATION` using method
ENV.setValueForEnvironmentVariable("Debug")
// Set value for key `BUILD_CONFIGURATION` using subscript
ENV["BUILD_CONFIGURATION"] = "Release"
You can reset/remove a value for an environment variable using either removeValueForEnvironmentVariable
or the subscript for syntatic sugar
let ENV = SwiftEnv()
// Remove value for key `TEST_MODE` using method
ENV.removeValueForEnvironmentVariable("TEST_MODE") = nil
// Remove value for key `BUILD_MODE` using subscript
ENV["BUILD_MODE"] = nil
If you would like to contribute, please consult the contributing guidelines for details. Also check out the GitHub issues for major milestones/enhancements needed.
SwiftEnv is released under the MIT license. See LICENSE for details