let id = model.persistentModelID
let descriptor = FetchDescriptor<cache>(
predicate: #Predicate { $0.cacheOf.persistentModelID == id }
// predicate: #Predicate { $0.cacheOf.id == id } or this
)
let result = (try? self.modelContext.fetch(descriptor) // 💥 crash here!
.first)
return result
Some update on this! So turns out, I was fetching a model that was just created. The system can't find the model. I guess this was a cache miss in swiftData?!
To Fix This: In your modelActor try? self.modelContext.save()
basically, you want the modelContext to write into disk to create the persistentModelID
Good luck!