CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

Build-in CoreStoreObject to JSON encoding

Open DimaZava opened this issue 7 years ago • 2 comments

DimaZava avatar Jul 17 '18 11:07 DimaZava

might try this:

extension CoreStoreObject {
    func toDict() -> Dictionary<String, Any> {
        var dict = Dictionary<String, Any>()
        self.cs_toRaw().entity.attributesByName.forEach { (field, value) in
            dict[field] = self.cs_toRaw().getValue(forKvcKey: field)
        }
        return dict
    }
}

HaiyuanZh avatar Mar 23 '19 08:03 HaiyuanZh

If this is ever done, it should be in the form of automatic conformance to Encodable. However, given that encoding inverse relationships would lead to infinite recursion, I think the entire concept of encoding single objects is flawed.

Personally, I think it would make more sense to implement an NSAtomicStore subclass for JSON, along the lines of the existing XML store. I don’t think that needs to be part of CoreStore to work, either.

Saklad5 avatar May 06 '20 15:05 Saklad5