D
D
deleted-mezhevikin2013-08-14 22:25:56
Objective-C
deleted-mezhevikin, 2013-08-14 22:25:56

How to work with temporary data in CoreData?

There is an application with two UITableViewController - FirstViewController and SecondViewController.
The models have one entity People.
The FirstViewController displays all data from People (persistent storage).
In the SecondViewController, data is loaded from the server in the form of json, an array of People entities is formed from json and they are also displayed.
On click of the SecondViewController cell, the record (only the selected one) should be stored in persistent storage.
I tried to make different NSManagedObjectContext for FirstViewController and SecondViewController, but it turned out that it is impossible to transfer an NSManagedObject object from one context to another.
Now in the SecondViewController I form an array of NSDictionary objects from json, on click I already transfer it to NSManagedObject and save it.
It turns out a certain heterogeneity of working with data.
Can this problem be solved in another way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
deleted-mezhevikin, 2013-08-24
@deleted-mezhevikin

Found a working solution to my question.
The solution is to recreate the NSManagedObject in a new context, i.e. a new empty object is created, attributes and relationships are copied into it.
I previously found a similar solution in one book, but it did not work correctly with NSManagedObject with multiple related objects.
At first glance, this solution seems to work quite quickly and adequately.

A
An, 2013-08-14
@Flanker_4

And what for you temporary objects bring in storage.
Why not just keep them in memory, and after the user selects, enter only the selected one?

H
hybridcattt, 2013-08-18
@hybridcattt

If this option is suitable, it would be best not to create entities when displaying the table in the SecondViewController, but to make the parsed data from json the source for the table. When the user selects a row, create one NSManagedObject in the desired context and save it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question