Structure
DotEnvFile
Reads dotenv (
.env) files and loads them into the current process.struct DotEnvFile
Overview
let fileio: NonBlockingFileIO
let file = try await DotEnvFile.read(path: ".env", fileio: fileio)
for line in file.lines {
print("\(line.key)=\(line.value)")
}
file.load(overwrite: true) // loads all lines into the process
Dotenv files are formatted using KEY=VALUE syntax. They support comments using the # symbol. They also support strings, both single and double-quoted.
FOO=BAR
STRING='Single Quote String'
# Comment
STRING2="Double Quoted\nString"
Single-quoted strings are parsed literally. Double-quoted strings may contain escaped newlines that will be converted to actual newlines.
Topics
Structures
DotEnvFile.LineRepresents aKEY=VALUEpair in a dotenv file.
Instance Properties
linesAllKEY=VALUEpairs found in the file.
Instance Methods
load(overwrite:)Loads this file’sKEY=VALUEpairs into the current process.
Type Methods
load(for:fileio:logger:)Reads the dotenv files relevant to the environment and loads them into the process.load(for:on:fileio:logger:)Reads the dotenv files relevant to the environment and loads them into the process.load(for:on:logger:)Reads the dotenv files relevant to the environment and loads them into the process.load(path:fileio:logger:)Reads the dotenv files relevant to the environment and loads them into the process.load(path:fileio:on:overwrite:)Reads a dotenv file from the supplied path and loads it into the process.load(path:fileio:overwrite:)Reads a dotenv file from the supplied path and loads it into the process.load(path:on:fileio:logger:)Reads the dotenv files relevant to the environment and loads them into the process.load(path:on:logger:)Reads the dotenv files relevant to the environment and loads them into the process.read(path:fileio:)Reads a dotenv file from the supplied path.read(path:fileio:on:)Reads a dotenv file from the supplied path.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype