I have read lot of topics about this issue but did not really find an appropriate answer. I want to create an instance of NSManagedObject
without having context.
Here is the reason: app gets soap answer from the server. This answer must be saved into Core Data. The answer looks like a tree.
My idea is to override init
for each entity so it takes data. After that I'll be able to create root entity and creation of root entity will call creation of another entity and so on.
Part of app that is responsible for a making requests is implemented through generics. There is protocol that describes init
that each response class must have, e. g.:
public protocol Parsable {
init(data: Data)
}
So as you can see there is no room for context here. Instead I want to create all these entities and save it into the context in one go.
The alternative solution here is to make duplicated classes, fill it with response, and then copy it into my Core Data entities. But this is unnecessary duplication that I would like to avoid.
Any ideas will be appreciated.