Contents

EntityURLRepresentation

The type that provides the URL for an app entity.

Declaration

struct EntityURLRepresentation<Entity> where Entity : AppEntity

Overview

If you adopt the URLRepresentableEntity protocol in an app entity, use this type to build the URL for your entity. Construct the type as a Swift string that contains characters suitable for use in a URL. To incorporate content from your app entity’s properties into the URL, include a key path to the property in your string. The following example shows an app entity that represents a specific inventory item. Before returning the URL, this type replaces the \(\.$contentID) key path with the value in the contentID property.

struct MyAppData: AppEntity, URLRepresentableEntity {
    static let defaultQuery = MyAppDataQuery()

    @Property(title: "Content ID")
    var contentID: String

    static var urlRepresentation = URLRepresentation("https://example.com/note=\(.$contentID)")
}

Make sure the properties you include in your URL representation contain a URL-friendly type. The system automatically converts properties of type String, Int, and URL to values suitable for inclusion in a URL. To incorporate other types, implement the CustomURLRepresentationParameterConvertible protocol in the type.

Topics

Initializers

See Also

Universal link navigation