Skip to content
Josh Wright edited this page Jan 14, 2021 · 4 revisions

Env

Handles any environment info of your application. Loads any environment variables from the file a .env or .{APP_ENV} if APP_ENV is set in the current environment.

@dynamicMemberLookup public struct Env: Equatable

Variables are accessed via .get. Supports dynamic member lookup.

// .env file:
SOME_KEY=secret_value
OTHER_KEY=123456

// Swift code
let someVariable: String? = Env.current.get("SOME_KEY")

// Dynamic member lookup
let otherVariable: Int? = Env.OTHER_KEY

Inheritance

Equatable

Properties

name

The environment file location of this application. Additional env variables are pulled from the file at '.{name}'. This defaults to env or APP_ENV if that is set.

let name: String

all

All environment variables available to the program.

var all: [String: String]

current

The current environment containing all variables loaded from the environment file.

var current: Env

Methods

get(_:)

Returns any environment variables loaded from the environment file as type T:​ EnvAllowed. Supports String, Int, Double, and Bool.

public func get<S: StringInitializable>(_ key: String) -> S?

Parameters

  • key: The name of the environment variable.

Returns

The variable converted to type S. nil if the variable doesn't exist or it cannot be converted as S.

Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally