0

This is a bit of a tough question to explain. I've been looking for an answer to this over two weeks but I couldn't find a solution for this use case.

Before I get into the nitty gritty details, please have a look at this image. enter image description here

The user is presented with the Main List view at first. The data (patient records) shown in this view is fetched from an API. One important thing to note here is that the data is retrieved only for the current date. There are records for the past days and days to come in the database but by default the data is of current date. After I call the API and get the data, I create objects out of them and store those objects in Core Data. Then I fetch them from my core data model and display them in the table view.

Each Patient record in Main List is actually a group of smaller records. When the user taps on a record, he is taken to a Sub List where you can see all those smaller record details. He can also edit, delete these smaller record items.

Here's where I need help. While the user is in the Sub List he can change the date from within that view. And it should display the small record details for the newly selected date. This means calling the API again, sending the selected date as a parameter and get the data for that date and display them in the Sub List view.

But this whole date changing operation has no effect on the Main List's data. In other words, the Main List's current date's data should not change even though the date was changed inside the Sub List. If/when the user taps the back button to get to the Main List, the old, current date's data should be readily available as he left it and the new data in the Sub List view is discarded upon leaving that view.

Another thing is although the new data is temporary, the user still needs to be able to edit those records. It's not simply for display purposes. That's why I need to add them to core data.

My question is once I get the data for the new date within the Sub List, is there a way I can persist that data temporarily without affecting my original data set?

I'd really appreciate any help.

Thank you.

4

1 回答 1

1

当您说“从 API 获取”时,我认为这意味着通过网络从 Web API 获取。正确的?

在回答您提出的问题时:这对于单独的 NSManagedObjectContext 来说似乎是一个很好的案例。您可以为您的子列表创建一个新的 MOC,然后在完成后销毁该 MOC。这将允许您在 Sub List 视图中使用 Core Data,但更改不会保留在您的数据存储中。

另一种方法是在永久存储或内存中创建一个重复的持久存储。

但是,听起来 Core Data 不是这项工作的正确工具。如果您从 Web 服务中提取数据,并在不同的时间段内保留不同的数据块,那么您将花费更多时间与 Core Data 抗争。

于 2015-03-03T19:02:54.060 回答