Instance Methodswift 6.0.1Swift

    appending(path:)

    Returns a new key path created by appending the given key path to this one.

    func appending<Root>(path: AnyKeyPath) -> PartialKeyPath<Root>? where Self == PartialKeyPath<Root>

    Parameters

    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.

    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.

    Other members in extension

    Instance members