init(exporting:importing:)
an entity and an IntentPerson.
Declaration
init(exporting: @escaping @Sendable (Item) async throws -> IntentValue, importing: @escaping @Sendable (IntentValue) async throws -> Item)Parameters
- exporting:
A closure that converts an entity to an IntentPerson.
- importing:
A closure that converts an IntentPerson back to an entity.
Example
struct ContactEntity: AppEntity, Transferable {
static var transferRepresentation: some TransferRepresentation {
ValueRepresentation(
exporting: { contact in
IntentPerson(
identifier: .applicationDefined(contact.id),
name: .displayName(contact.name),
handle: .init(emailAddress: contact.email)
)
},
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 ?? ""
)
}
)
}
}