Swiftpack.co - Package - eman6576/SwiftEnv

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

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

1.1.0 - Nov 2, 2017

Release on 11-02-2017.

Added

1 Repo icon

1.0.0 - Oct 26, 2017

In this release:

  1. Read values from environment variables
  2. Set values to environment variables
  3. Reset/Remove values for environment variables
  4. Swift 4 support