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")
}
}
-
The key used to differentiate the element.
Declaration
Swift
public var key: AnyHashable?
-
The wrapped element.
Declaration
Swift
public var wrapped: Element
-
Creates a new
Keyed
element with the provided key and wrapped element.Declaration
Swift
public init(key: AnyHashable?, wrapping: Element)
-
Declaration
Swift
public var content: ElementContent { get }
-
Declaration
Swift
public func backingViewDescription(with context: ViewDescriptionContext) -> ViewDescription?