Structure
DotEnvFile
Reads dotenv (
.env) files and loads them into the current process.struct DotEnvFile
Overview
let file = try await DotEnvFile.read(path: ".env")
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
struct LineRepresents aKEY=VALUEpair in a dotenv file.
Instance Properties
let lines: [Line]AllKEY=VALUEpairs found in the file.
Instance Methods
func load(overwrite: Bool)Loads this file’sKEY=VALUEpairs into the current process.
Type Methods
static func load(for: Environment) asyncReads the dotenv files relevant to the environment and loads them into the process.static func load(path: String) asyncReads the dotenv files relevant to the environment and loads them into the process.static func load(path: String, overwrite: Bool) async throwsReads a dotenv file from the supplied path and loads it into the process.static func read(path: String) async throws -> DotEnvFileReads a dotenv file from the supplied path.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype