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.SyntaxError if the file is invalid

    Throws

    NSError if the file does not exist

    Declaration

    Swift

    public convenience init(contentsOfFile path: String,
        encoding: String.Encoding = String.Encoding.utf8) throws

    Parameters

    contentsOfFile

    Path of file to read

    encoding

    Encoding of file

    Return Value

    A dictionary with parsed results

  • Parse the string withString as TOML.

    Throws

    TomlError.SyntaxError if the file is invalid

    Declaration

    Swift

    public convenience init(withString string: String) throws

    Parameters

    withString

    A 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

    key

    Array of strings

    value

    Value to set

  • Add a sub-table

    Declaration

    Swift

    public func setTable(key: [String])

    Parameters

    key

    Array of strings indicating table path

  • Check if the TOML document contains the specified key.

    Declaration

    Swift

    public func hasKey(key: [String], includeTables: Bool = true) -> Bool

    Parameters

    key

    Key path to check

    includeTables

    Include 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...) -> Bool

    Parameters

    key

    Key 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]) -> Bool

    Parameters

    key

    Key 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...) -> Bool

    Parameters

    key

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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

    parent

    Root 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

    parent

    Root 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]) -> Toml

    Parameters

    from

    Key path to create table from

    Return Value

    Toml table of all keys beneath the specified path

  • Get a TOML table from the document

    Declaration

    Swift

    public func table(_ path: String...) -> Toml?

    Parameters

    path

    Key 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

    path

    Key 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

    path

    Key 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

    path

    Key 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