Since @Model is a macro it would do something special (custom logic) for every member property to persist it.
Workaround
Create a struct ItemRecord with the same properties
Populate ItemRecord with Item
Conform ItemRecord to Codable and Transferable
Let the Item have a way to conveniently create ItemRecord
Use ItemRecord to drag and drop or for other transferable functionalities (item.record)
Code
@Model
final class Item {
let createdAt: Date
//For convenience
var record: ItemRecord {
ItemRecord(item: self)
}
init() {
self.createdAt = .now
}
}
struct ItemRecord: Codable, Transferable {
let createdAt: Date
init(item: Item) {
createdAt = item.createdAt
}
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .myCustomType)
}
}
Topic:
Privacy & Security
SubTopic:
General
Tags: