Toml
public class Toml : CustomStringConvertible, SetValueProtocol, @unchecked Sendable
Data parsed from a TOML document
-
Set of all key paths in the TOML document.
Declaration
Swift
private(set) public var keyNames: Set<Path> { get } -
Optional prefix path for scoped table access.
Declaration
Swift
private(set) public var prefixPath: Path? { get } -
Set of all table paths in the TOML document.
Declaration
Swift
private(set) public var tableNames: Set<Path> { get } -
Creates an empty TOML document.
Declaration
Swift
public init() -
Read the specified TOML file from disk.
Throws
TomlError.SyntaxErrorif the file is invalidThrows
NSErrorif the file does not existDeclaration
Swift
public convenience init(contentsOfFile path: String, encoding: String.Encoding = String.Encoding.utf8) throwsParameters
contentsOfFilePath of file to read
encodingEncoding of file
Return Value
A dictionary with parsed results
-
Parse the string
withStringas TOML.Throws
TomlError.SyntaxErrorif the file is invalidDeclaration
Swift
public convenience init(withString string: String) throwsParameters
withStringA string with TOML document
Return Value
A dictionary with parsed results
-
Set the value for the the given key path
Declaration
Swift
public func set(value: Any, for key: [String])Parameters
keyArray of strings
valueValue to set
-
Add a sub-table
Declaration
Swift
public func setTable(key: [String])Parameters
keyArray of strings indicating table path
-
Check if the TOML document contains the specified key.
Declaration
Swift
public func hasKey(key: [String], includeTables: Bool = true) -> BoolParameters
keyKey path to check
includeTablesInclude tables and inline tables in key path check
Return Value
True if key exists; false otherwise
-
Check if the TOML document contains the specified key.
Declaration
Swift
public func hasKey(_ key: String...) -> BoolParameters
keyKey path to check
Return Value
True if key exists; false otherwise
-
Check if the TOML document contains the specified table.
Declaration
Swift
public func hasTable(_ key: [String]) -> BoolParameters
keyKey path to check
Return Value
True if table exists; false otherwise
-
Check if the TOML document contains the specified table.
Declaration
Swift
public func hasTable(_ key: String...) -> BoolParameters
keyKey path to check
Return Value
True if key exists; false otherwise
-
Get an array of type T from the TOML document
Declaration
Swift
public func array<T>(_ path: [String]) -> [T]?Parameters
pathKey path of array
Return Value
An array of type [T]
-
Get an array of type T from the TOML document
Declaration
Swift
public func array<T>(_ path: String...) -> [T]?Parameters
pathKey path of array
Return Value
An array of type [T]
-
Get a boolean value from the specified key path.
Declaration
Swift
public func bool(_ path: [String]) -> Bool?Parameters
pathKey path of value
Return Value
boolean value of key path
-
Get a boolean value from the specified key path.
Declaration
Swift
public func bool(_ path: String...) -> Bool?Parameters
pathKey path of value
Return Value
boolean value of key path
-
Get a date value from the specified key path.
Declaration
Swift
public func date(_ path: [String]) -> Date?Parameters
pathKey path of value
Return Value
date value of key path
-
Get a date value from the specified key path.
Declaration
Swift
public func date(_ path: String...) -> Date?Parameters
pathKey path of value
Return Value
date value of key path
-
Get a double value from the specified key path.
Declaration
Swift
public func double(_ path: [String]) -> Double?Parameters
pathKey path of value
Return Value
double value of key path
-
Get a double value from the specified key path.
Declaration
Swift
public func double(_ path: String...) -> Double?Parameters
pathKey path of value
Return Value
double value of key path
-
Get a int value from the specified key path.
Declaration
Swift
public func int(_ path: [String]) -> Int?Parameters
pathKey path of value
Return Value
int value of key path
-
Get a int value from the specified key path.
Declaration
Swift
public func int(_ path: String...) -> Int?Parameters
pathKey path of value
Return Value
int value of key path
-
Get a string value from the specified key path.
Declaration
Swift
public func string(_ path: [String]) -> String?Parameters
pathKey path of value
Return Value
string value of key path
-
Get a string value from the specified key path.
Declaration
Swift
public func string(_ path: String...) -> String?Parameters
pathKey path of value
Return Value
string value of key path
-
Get a dictionary of all tables 1-level down from the given key path. To get all tables at the root level call with no parameters.
Declaration
Swift
public func tables(_ parent: [String]) -> [String : Toml]Parameters
parentRoot key path
Return Value
Dictionary of key names and tables
-
To get all tables at the root level.
Declaration
Swift
public func tables() -> [Toml]Return Value
Array of tables
-
Get a dictionary of all tables 1-level down from the given key path. To get all tables at the root level call with no parameters.
Declaration
Swift
public func tables(_ parent: String...) -> [String : Toml]Parameters
parentRoot key path
Return Value
Dictionary of key names and tables
-
Return a TOML table that contains everything beneath the specified path.
Declaration
Swift
public func table(from path: [String]) -> TomlParameters
fromKey path to create table from
Return Value
Tomltable of all keys beneath the specified path -
Get a TOML table from the document
Declaration
Swift
public func table(_ path: String...) -> Toml?Parameters
pathKey path of value
Return Value
Table of name
path -
Get a value of type T from the specified key path.
Declaration
Swift
public func value<T>(_ path: [String]) -> T?Parameters
pathKey path of value
Return Value
value of key path
-
Get a value of type T from the specified key path.
Declaration
Swift
public func value<T>(_ path: String...) throws -> T?Parameters
pathKey path of value
Return Value
value of key path
-
Get the value specified by path as a string
Declaration
Swift
public func valueDescription(_ path: [String]) -> String?Parameters
pathKey path of value
Return Value
value of key path as a string
-
Get a string representation of the TOML document
Declaration
Swift
public var description: String { get }Return Value
String version of TOML document
View on GitHub
Install in Dash