SwiftUI holding reference to deleted core data object causing crash

后端 未结 6 638
谎友^
谎友^ 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 04:52

    I had the same issue recently. Adding an entity property to the view fixed it.

    ForEach(entities, id: \.self) { entity in
        Button(action: {
    
        }) {
            MyCell(entity: entity)
        }
    }
    

    To

    ForEach(entities, id: \.self) { entity in
        Button(action: {
    
        }) {
            MyCell(entity: entity, property: entity.property)
        }
    }
    

    I suspect that the nullable Core Data entity is the cause of the issue, where as adding a non-nil property as a var (e.g, var property: String) fixed it

提交回复
热议问题