Post

Replies

Boosts

Views

Activity

Reply to SwiftData ModelContext Fetch Crashing
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!
1w
Reply to SwiftData ModelContext Fetch Crashing
It seems to crash with any SwiftData related id, but it's fine when just using the primitive values 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
Sep ’24