开发者

Core Data Best Practice for Importing Data

开发者 https://www.devze.com 2023-04-10 02:57 出处:网络
I\'ve got an application (iPad & Mac Lion) which uses CoreData for its storage. The app imports data from a number of hardware devices, decodes the data into a number of discrete events, and prese

I've got an application (iPad & Mac Lion) which uses CoreData for its storage. The app imports data from a number of hardware devices, decodes the data into a number of discrete events, and presents the list of events to the user, who then has the choice to select which events are saved.

At the moment, I create a non-CoreData object for each event, and then convert the ones selected by the user to CoreData enti开发者_高级运维ties to be saved in the store. This means I've basically got two classes for each object; one managed CoreData object, and another non-managed object that represents the event before the user selects it.

I suspect there must be a better, lower code-overhead, (read: more manageable) way to do this:

  • Can I create core data entities without having them saved into the store, and then only save the ones selected by the user?
  • Or is there some other way to structure this, using CoreData?


This is what Managed Object Contexts are for. :-) Create an "import context" separate from the normal data context that displays the actual data the user has in their "database". Create all the objects (and don't save) in that context, let the user drop the ones he/she doesn't want, then merge the contexts when done with import and save.

0

精彩评论

暂无评论...
验证码 换一张
取 消