Skip to content

An easy to use interface for accessing environment variables with Swift

License

Notifications You must be signed in to change notification settings

the-freshlord/SwiftEnv

Repository files navigation

SwiftEnv: Easy Access To Enviroment Variables

Build Status codecov Swift 4.0 Swift Package Manager compatible DUB platform

An easy to use interface for accessing environment variables with Swift

Installation

Swift Package Manager

You can add this to your Package.swift manifest with

.package(url: "https://github.com/eman6576/SwiftEnv.git", from: "1.1.0")

Usage

Read

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"]

Write

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"

Reset

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

Contributing

If you would like to contribute, please consult the contributing guidelines for details. Also check out the GitHub issues for major milestones/enhancements needed.

License

SwiftEnv is released under the MIT license. See LICENSE for details

About

An easy to use interface for accessing environment variables with Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published