init(importing:)
Creates a value representation that imports a system intent value into an entity.
Declaration
init(importing: @escaping @Sendable (IntentValue) async throws -> Item)Parameters
- importing:
A closure that converts a system intent value to an entity.
Discussion
Use this initializer when your entity can be created from a system type, but has no meaningful representation to export back out. The entity’s metadata declares the system type as importable only, and the entity is never offered for export as that type.
Example
struct LocationEntity: AppEntity, Transferable {
static var transferRepresentation: some TransferRepresentation {
IntentValueRepresentation(
importing: { place in
guard let coordinate = place.coordinate else {
throw ImportError.missingCoordinate
}
return LocationEntity(
name: place.commonName ?? "Unknown Location",
latitude: coordinate.latitude,
longitude: coordinate.longitude
)
}
)
}
}