I’d like to use the @ModelActor directive on an actor and have it accept parameters in its constructor.
Ideally, something like this:
@ModelActor
actor SomeActor {
public let someVariable: String
init(modelContainer: SwiftData.ModelContainer, someVar: String) {
self.someVariable = someVar
self.init(modelContainer: modelContainer)
}
}
However, this approach doesn’t work:
1. The code fails with the error: Actor-isolated property 'someVariable' cannot be mutated from a nonisolated context.
2. If I try initializing modelExecutor and modelContainer directly instead of calling self.init, the macro’s initializer fails with: Return from initializer without initializing all stored properties.
I don’t want to initialize variables in a separate function, as it complicates references to those variables.
Is there any solution to this?