You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to figure out how to implement a CoreStoreObject subclass that also needs to conform to Decodable protocol. What I came up with is the code below.
`
class TestObject: CoreStoreObject, Decodable {
let title = Value.Optional("title", initial: nil)
However I'm having error;
❗ [CoreStore: Assertion Failure] Value.swift:373 value
↪︎ Attempted to access values from a 'Test' meta object. Meta objects are only used for querying keyPaths and infering types.
I think issue is related to the init(asMeta:...), init(rawObject:...) methods' implementation.
What is the proper way to implement these methods?
Thanks.
The text was updated successfully, but these errors were encountered:
As mentioned somewhere in the discussion in mogenerator's prototype for Codable support, NSManagedObjects generally do not really play well with Encodable because the init(decoder:) needs to be implemented, while NSManagedObject's init(context:) needs an instance of the NSManagedObjectContext where the object will be added. (Basically you can call init(decoder:) many times without side effects, but init(context:) does)
You are hitting the same limitation with CoreStoreObject here, where it needs the context (via the NSManagedObject in init(rawObject:)).
You can borrow the techniques used in the mogenerator proposal above, but at that point I would recommend you to use ImportableUniqueObjects instead as they are much much more simple.
I solved my issue by creating two different objects. They conform CoreStoreObject and Decodable seperately. Added additional methods to make required mapping between them. Thanks for the information.
Hello,
I'm trying to figure out how to implement a CoreStoreObject subclass that also needs to conform to Decodable protocol. What I came up with is the code below.
`
class TestObject: CoreStoreObject, Decodable {
let title = Value.Optional("title", initial: nil)
}
`
However I'm having error;
❗ [CoreStore: Assertion Failure] Value.swift:373 value
↪︎ Attempted to access values from a 'Test' meta object. Meta objects are only used for querying keyPaths and infering types.
I think issue is related to the
init(asMeta:...), init(rawObject:...)
methods' implementation.What is the proper way to implement these methods?
Thanks.
The text was updated successfully, but these errors were encountered: