Hi all,
There appears to be some changes to how ModelActors are implemented in Beta 7 of Xcode 15. In Beta 6, we had the DefaultModelExecutor object which we used to assign to the ModelActor's executor property. A simple example is shown below:
final actor SimpleModelActor: ModelActor {
let executor: any ModelExecutor
init(modelContainer: ModelContainer) {
let modelContext = ModelContext(modelContainer)
executor = DefaultModelExecutor(context: modelContext)
}
func addItem() {
let newItem = Item(timestamp: Date())
context.insert(newItem)
try! context.save()
}
....
}
However, it seems that the DefaultModelExecutor class has been removed for Beta 7, without any real replacement. Anyone know how to implement a ModelActor in the new beta?
Thanks in advance.
@ModelActor
actor CountryModelActor {
init(container: ModelContainer) {
modelContainer = container
let context = ModelContext(container)
modelExecutor = DefaultSerialModelExecutor(modelContext: context)
}
func newItem() {
let item = Item(timestamp: .now, name: "\(Int.random(in: 0...3))")
modelContext.insert(item)
try! modelContext.save()
}
}