crash accessing @NSManaged primitiveValue

Viewed 21

I'm trying to observe an @NSManaged object property change. I know that is not possible to write a didSet, but searching online I found the solution explained in this video that 99% of times works: https://www.youtube.com/watch?v=sxWBPKGFo_A

In 1% of times leads to a crash accessing the primitiveValue(forKey). In the monitoring console the crash message I have is only the property names itself, but when happen during the development, the error message is that I'm trying to unwrap a nil value, but this is strange since I have a property defined as follow

@objc public var deleted_: Bool{
        set{
            willChangeValue(forKey: "deleted_")
            setPrimitiveValue(newValue, forKey: "deleted_")
            didChangeValue(forKey: "deleted_")
            if newValue{
                deleteDescendants()
            }
        }
        get{
            willAccessValue(forKey: "deleted_")
            let value = primitiveValue(forKey: "deleted_") as? Bool ?? false
            didAccessValue(forKey: "deleted_")
            return value
        }
    }

It's not optional and in the model file (.xcdatamodel) I even set the default value for that property declared as non-optional too. How can this variable can be nil? I even enable the concurrency debug for CoreData and when crashes don't tell me the concurrency message "AllIsLeftToUsIsHonor".

I think I cannot understand well what the primitiveValue does? Someone has experienced the same issue?

Thank you very much

0 Answers
Related