So, this actually works for me...
If I right click on a gallery item on iPad and type "send this to " it will grab all items on screen and put them into a message.
Here is what I have in my UICollectionView:
public func collectionView(
_ collectionView: UICollectionView,
appEntityIdentifierForItemAt indexPath: IndexPath
) -> EntityIdentifier? {
guard let item = dataSource?.itemIdentifier(for: indexPath) else { return nil }
guard let fileIdentifier = try? FileEntityIdentifier.file(url: <URL>) else { return nil }
return EntityIdentifier(for: <ENTITY>.self, identifier: fileIdentifier)
}
Note using the "FileEntityIdentifier" with the file's URL.
Also, the that gets provided happens to conform to @AppEntity(schema: .files.file)
My Transfer representations are just the following:
public static var transferRepresentation: some TransferRepresentation {
FileRepresentation(
contentType: .image,
exporting: { entity in
print(" INT Exporting File Entity as File Representation")
guard let url = try await entity.id.fileURL else {
throw Errors.unableToRetrieveURL
}
return SentTransferredFile(url)
},
importing: { received in
let attributes = try? FileManager.default.attributesOfItem(atPath: received.file.path())
let creationDate = attributes?[.creationDate] as? Date
let modificationDate = attributes?[.modificationDate] as? Date
print("INT Attempting import of Image Entity from File Representation")
return <ENTITY>(
id: try FileEntityIdentifier.file(url: received.file),
creationDate: creationDate,
fileModificationDate: modificationDate,
name: received.file.lastPathComponent
)
})
}
Topic:
Machine Learning & AI
SubTopic:
Apple Intelligence
Tags: