For anyone else seeing this, from the related Github thread, it seems to be due to the custom init defined.
Temporarily making the init only accessible via a static method seems to be a temporary bypass to avoid the build error
https://github.com/apple/swift/issues/67823#issuecomment-1673842437
add this inside your swift model, and only instantiate the model via a static method when calling from the parent package.
public static func create(value: String) -> Note {
Note(value)
}
hopefully this is fixed in the next release.
Post
Replies
Boosts
Views
Activity
Did you ever find a solution? im having the same issue, where after the app is restarted, all the data is lost, but only once I start accessing the swift data from the background context.
Same issue here. Assuming it will be fixed once the new xcode beta comes out.
after more debugging, calling the code inside onappear instead of init seems to have solved the issue
I also tried
let servers = Query(FetchDescriptor<MY_DATA_CLASS>()).wrappedValue
but get the error
Set a .modelContext in view's environment to use Query
I have this in the top of the class, but I assume it hasnt been initialized yet?
@Environment(\.modelContext) private var modelContext
Beta 2 is out and seems to have added support for SwiftData. 🤷♂️ at least it works fine for me.