How to use swift 4 Codable in Core Data?
问题 Codable seems a very exciting feature. But I wonder how we can use it in Core Data? In particular, is it possible to directly encode/decode a JSON from/to a NSManagedObject? I tried a very simple example: and defined Foo myself: import CoreData @objc(Foo) public class Foo: NSManagedObject, Codable {} But when using it like this: let json = \"\"\" { \"name\": \"foo\", \"bars\": [{ \"name\": \"bar1\", }], [{ \"name\": \"bar2\" }] } \"\"\".data(using: .utf8)! let decoder = JSONDecoder() let foo