class PartialKeyPath<Root>
Inheritance |
AnyKeyPath, Equatable, Hashable, _AppendKeyPath
View Protocol Hierarchy →
|
---|---|
Import | import Swift |
Instance Methods
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Appending the key path passed as path
is successful only if the
root type for path
matches this key path's value type. This example
creates key paths from Array<Int>
to String
and from String
to
Int
, and then tries appending each to the other:
let arrayDescription: PartialKeyPath<Array<Int>> = \.description
let stringLength: PartialKeyPath<String> = \.count
// Creates a key path from `Array<Int>` to `Int`
let arrayDescriptionLength = arrayDescription.appending(path: stringLength)
let invalidKeyPath = stringLength.appending(path: arrayDescription)
// invalidKeyPath == nil
The second call to appending(path:)
returns nil
because the root type of arrayDescription
, Array<Int>
, does not
match the value type of stringLength
, Int
.
path
: The key path to append.
Returns: A key path from the root of this key path and the value type
of path
, if path
can be appended. If path
can't be appended,
returns nil
.
Declaration
func appending<Root>(path: AnyKeyPath) -> PartialKeyPath<Root>? where PartialKeyPath<Root> == PartialKeyPath<Root>
Declared In
_AppendKeyPath
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Calling appending(path:)
results in the same key path as if the
given key path had been specified using dot notation. In the following
example, keyPath1
and keyPath2
are equivalent:
let arrayDescription = \Array<Int>.description
let keyPath1 = arrayDescription.appending(path: \String.count)
let keyPath2 = \Array<Int>.description.count
path
: The key path to append.
Returns: A key path from the root of this key path to the value type of
path
.
Declaration
func appending<Root, Value, AppendedValue>(path: KeyPath<Value, AppendedValue>) -> KeyPath<Root, AppendedValue> where PartialKeyPath<Root> : KeyPath<Root, Value>
Declared In
_AppendKeyPath
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Calling appending(path:)
results in the same key path as if the
given key path had been specified using dot notation.
path
: The key path to append.
Returns: A key path from the root of this key path to the value type of
path
.
Declaration
func appending<Root, Value, AppendedValue>(path: ReferenceWritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> where PartialKeyPath<Root> == KeyPath<Root, Value>
Declared In
_AppendKeyPath
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Calling appending(path:)
results in the same key path as if the
given key path had been specified using dot notation.
path
: The key path to append.
Returns: A key path from the root of this key path to the value type of
path
.
Declaration
func appending<Root, Value, AppendedValue>(path: WritableKeyPath<Value, AppendedValue>) -> WritableKeyPath<Root, AppendedValue> where PartialKeyPath<Root> == WritableKeyPath<Root, Value>
Declared In
_AppendKeyPath
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Appending the key path passed as path
is successful only if the
root type for path
matches this key path's value type. This example
creates a key path from Array<Int>
to String
, and then tries
appending compatible and incompatible key paths:
let arrayDescription: PartialKeyPath<Array<Int>> = \.description
// Creates a key path from `Array<Int>` to `Int`
let arrayDescriptionLength = arrayDescription.appending(path: \String.count)
let invalidKeyPath = arrayDescription.appending(path: \Double.isZero)
// invalidKeyPath == nil
The second call to appending(path:)
returns nil
because the root type
of the path
parameter, Double
, does not match the value type of
arrayDescription
, String
.
path
: The key path to append.
Returns: A key path from the root of this key path to the value type
of path
, if path
can be appended. If path
can't be appended,
returns nil
.
Declaration
func appending<Root, AppendedRoot, AppendedValue>(path: KeyPath<AppendedRoot, AppendedValue>) -> KeyPath<Root, AppendedValue>? where PartialKeyPath<Root> == PartialKeyPath<Root>
Declared In
_AppendKeyPath
Returns a new key path created by appending the given key path to this one.
Use this method to extend this key path to the value type of another key
path. Appending the key path passed as path
is successful only if the
root type for path
matches this key path's value type.
path
: The reference writeable key path to append.
Returns: A key path from the root of this key path to the value type
of path
, if path
can be appended. If path
can't be appended,
returns nil
.
Declaration
func appending<Root, AppendedRoot, AppendedValue>(path: ReferenceWritableKeyPath<AppendedRoot, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue>? where PartialKeyPath<Root> == PartialKeyPath<Root>
Declared In
_AppendKeyPath
A partially type-erased key path, from a concrete root type to any resulting value type.