Structures
The following structures are available globally.
-
KeyPath
represents the path to a specific node in a tree of nested dictionaries.Can be created from string and array literals and can be joined by the
=>
operator.
See morelet a: KeyPath = "a" let b: KeyPath = ["a", "b"] let c: KeyPath = "a" => "b" => "c"
Declaration
Swift
public struct KeyPath
-
A key in a keyPath that may or may not be required.
Trying to access a invalid key in a dictionary with an
See moreOptionalKey
will usually result in a nil return value instead of a thrown error. UnlessisRequired
istrue
, in which it behaves as anormal
String
inside anormal
KeyPath
.Declaration
Swift
public struct OptionalKey
-
OptionalKeyPath
represents the path to a specific node in a tree of nested dictionaries.Can be created from string and array literals and can be joined by the
=>?
operator.let a: OptionalKeyPath = "a" let b: OptionalKeyPath = ["a", "b"] let c: OptionalKeyPath = "a" =>? "b" =>? "c"
Unlike
KeyPath
,OptionalKeyPath
allows each key to be either required or optional.isRequired
isfalse
by default.When a
KeyPath
is converted to a OptionalKeyPath,isRequired
is set totrue
.let c: OptionalKeyPath = "a" =>? "b" => "c" ^^ isRequired=true
In the above example
See more"c"
is inferred asKeyPath
, then converted toOptionalKeyPath
withisRequired = true
Declaration
Swift
public struct OptionalKeyPath