AnyKeyPath

class AnyKeyPath
Inheritance Hashable, _AppendKeyPath

Instance Variables

var hashValue Required

The hash value.

Declaration

var hashValue: Int

Instance Methods

func appending(path: AnyKeyPath) -> PartialKeyPath<Root>? Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root>(path: AnyKeyPath) -> PartialKeyPath<Root>? where Self == PartialKeyPath<Root>
func appending(path: KeyPath<AppendedRoot, AppendedValue>) -> KeyPath<Root, AppendedValue>? Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, AppendedRoot, AppendedValue>(path: KeyPath<AppendedRoot, AppendedValue>) -> KeyPath<Root, AppendedValue>? where Self == PartialKeyPath<Root>
func appending(path: ReferenceWritableKeyPath<AppendedRoot, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue>? Required

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.

  • Parameter path: The reference writeable key path to append.

Declaration

@inlinable public func appending<Root, AppendedRoot, AppendedValue>(path: ReferenceWritableKeyPath<AppendedRoot, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue>? where Self == PartialKeyPath<Root>
func appending(path: KeyPath<Value, AppendedValue>) -> KeyPath<Root, AppendedValue> Required

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
  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, Value, AppendedValue>(path: KeyPath<Value, AppendedValue>) -> KeyPath<Root, AppendedValue> where Self: KeyPath<Root, Value>
func appending(path: ReferenceWritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, Value, AppendedValue>(path: ReferenceWritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> where Self == KeyPath<Root, Value>
func appending(path: WritableKeyPath<Value, AppendedValue>) -> WritableKeyPath<Root, AppendedValue> Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, Value, AppendedValue>(path: WritableKeyPath<Value, AppendedValue>) -> WritableKeyPath<Root, AppendedValue> where Self == WritableKeyPath<Root, Value>
func appending(path: ReferenceWritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, Value, AppendedValue>(path: ReferenceWritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> where Self == WritableKeyPath<Root, Value>
func appending(path: WritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> Required

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.

  • Parameter path: The key path to append.

Declaration

@inlinable public func appending<Root, Value, AppendedValue>(path: WritableKeyPath<Value, AppendedValue>) -> ReferenceWritableKeyPath<Root, AppendedValue> where Self == ReferenceWritableKeyPath<Root, Value>
func hash(into hasher: inout Hasher) Required

Hashes the essential components of this value by feeding them into the given hasher.

  • Parameter hasher: The hasher to use when combining the components of this instance.

Declaration

final public func hash(into hasher: inout Hasher)

Type Variables

var rootType Required

The root type for this key path.

Declaration

var rootType: Any.Type
var valueType Required

The value type for this key path.

Declaration

var valueType: Any.Type

Type Methods

func ==(a: AnyKeyPath, b: AnyKeyPath) -> Bool Required

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Declaration

public static func ==(a: AnyKeyPath, b: AnyKeyPath) -> Bool