init(importing:)
Creates a value representation that imports an IntentPerson into an entity.
Declaration
init(importing: @escaping @Sendable (IntentValue) async throws -> Item)Parameters
- importing:
A closure that converts an IntentPerson to an entity.
Discussion
Use this initializer when your entity can be created from an IntentPerson, but has no meaningful representation to export back out. The entity’s metadata declares IntentPerson as importable only, and the entity is never offered for export as a person.
Example
struct ContactEntity: AppEntity, Transferable {
static var transferRepresentation: some TransferRepresentation {
ValueRepresentation(
importing: { person in
guard case let .applicationDefined(id) = person.identifier?.value else {
throw ImportError.missingIdentifier
}
return ContactEntity(
id: id,
name: person.name.displayString,
email: person.handle?.value ?? ""
)
}
)
}
}