Keyed

public struct Keyed : Element

Keyed allows providing a Hashable value which is used during view updates to uniquely identify content during the diff process between the old and new element structure.

This is useful if you have two elements of the same type at the same depth in the element hierarchy, and you’d like to differentiate between them, eg for appearance transition purposes.

Example

Keying the image returned, so that a transition occurs when changing between a placeholder image and an available photo.

func imageElement() -> Element {
    if let photo = self.photo {
        return Image(image: photo)
                .transition(.fade)
                .keyed("photo")
    } else {
        return Image(image: self.placeholder)
                .transition(.fade)
                .keyed("placeholder")
    }
}