Contents

snippet

The snippet that contains the view to display.

Declaration

@EntitySnippetContentBuilder<Self> static var snippet: Self.Body { get }

Discussion

Set the value of this property to a result builder that returns a CardSnippet type. Initialize the type with the SwiftUI view that displays the content from the provided entity. The following example shows an implementation of this property for an app entity that manages one of the app’s photos. The PhotoCardView is a custom SwiftUI view from the app that displays the provided entity and other relevant information.

extension PhotoEntity: SnippetRepresentableEntity {
    static var snippet: some EntitySnippetContent<Self> {
        CardSnippet(supportedFamilies: [.standard]) { photo, context in
            PhotoCardView(photo: photo)
        }
    }
}

If your view requires data that isn’t immediately available in your entity, prepare the data before you return the SwiftUI view from your snippet. For example, if you need to create custom images, create them before you return your view. Prepare data synchronously to ensure it’s available when you create your view. If you generate data asynchronously, it likely won’t be available in time.

See Also

Configuring the snippet