Storing NSManagedObject in a dictionary (NSDictionary)

后端 未结 3 1848
闹比i
闹比i 2021-01-31 20:05

I have a custom class, which is a subclass of NSManagedObject. I would like to store it in a dictionary, but when trying to do so I receive a Property list in

3条回答
  •  灰色年华
    2021-01-31 20:27

    A swift version in case anyone needs it

    import CoreData 
    extension NSManagedObject {
        func toDict() -> [String:Any] {
            let keys = Array(entity.attributesByName.keys)
            return dictionaryWithValues(forKeys:keys)
        }
    }
    

提交回复
热议问题