SwiftUI holding reference to deleted core data object causing crash

后端 未结 6 641
谎友^
谎友^ 2021-01-31 04:38

Im finding it impossible to use core data with SwiftUI, because as I pass a core data to a view observed object variable, the navigation link view will hold a reference to the o

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 05:12

    After some research online, it's clear to me that this crash can be caused by many things related to optionals. For me, I realized that declaring a non-optional Core Data attribute as an optional in the NSManagedObject subclass was causing the issue.

    Specifically, I have a UUID attribute id in Core Data that cannot have a default value, but is not optional. In my subclass, I declared @NSManaged public var id: UUID. Changing this to @NSManaged public var id: UUID? fixed the problem immediately.

提交回复
热议问题