SwiftUI holding reference to deleted core data object causing crash

后端 未结 6 599
谎友^
谎友^ 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条回答
  •  隐瞒了意图╮
    2021-01-31 05:07

    I encountered the same issue and did not really find a solution to the root problem. But now I "protect" the view that uses the referenced data like this:

    var body: some View {
        if (clip.isFault) {
            return AnyView(EmptyView())
        } else {
            return AnyView(actualClipView)
        }
    }
    
    var actualClipView: some View {
        // …the actual view code accessing various fields in clip
    }
    

    That also feelds hacky, but works fine for now. It's less complex than using a notification to "defer" deletion, but still thanks to sTOOs answer for the hint with .isFault!

提交回复
热议问题