views:

52

answers:

3

I am working on a project where the app parses data from an XML file, saves it to a persistent store and populates a table view. Every time the app opens, if there is internet connection available, the persistent store gets recycled and the XML is parsed again as it gets updated quite frequently. If no internet connection is available I'll just load the data from the latest parsing saved in my persistent store.

Once parsing is completed, users will then be able to browse through the objects and possibly mark them as favourites.

When this is done, I would like to be able to display these "marked as favourite" objects in a separate tab bar and keep them for as long as the user has them marked as favourites.

This could be done easily if the data from my persistent store wasn't being recycled so frequently but since that's not the case, I'd like to find the best way to:

  1. Create an additional persistent store;
  2. Be able to copy objects from one store to another

Or

Can you suggest a better way of implementing this?

Many thanks,

Rogerio

A: 

You can juts flag them as favorite and then don't delete or update them in the model. There is no need to copy the objects anywhere for something as simple as this.

Put a boolean flag in the entity called "favorite" and then if that flag is set to YES, don't update that entity on the next XML refresh and don't delete it.

Marcus S. Zarra
Hi Marcus, thanks for your response. It all makes sense but how would I go about dealing with objects that are not part of the XML parse anymore but are still marked as favourite by the user. Here's an example:- Feed parsed and object ABC saved to persistent storage, added to the "latest updates" view- Object ABC marked as favourite by user so it also gets added to the "favourite" view- XML file is updated and object ABC is no longer part of it. Next time the file is parsed it should disappear from "latest updates" view but still be available under "favourites" view.Thanks again!
Rog
A: 

hi rog, i don't know if you're problem is still up to date, but i tend to use an additional flag for your update list like marcus already explained. so you only need to compare the flags, which is done with a high performance compared two separate lists. especially you'll get a problem with you're memory if you keep every data twice.

mkind
A: 

For anyone interested in the solution to this problem, it turns out Marcus recommendation was spot on and way easier to implement than I initially anticipated.

The basic logic flow to make this work is:

  1. Download XML feed from web service

  2. Do a Fetch Request of objects flagged as favourite from persistent store

  3. Implement logic to compare uniqueID from new object being parsed and the ones saved as favourites.

  4. If a match is found, delete the existing/saved objected, continue with the parsing of the new one and mark it as favourite (this is only required if your object is likely to have additional/updated data otherwise simply ignore the object being parsed and keep to original one to save you the additional processing time).

  5. Use NSFetchedResultsController to manage updating the views for you. I personally have a separate view for my favourites and use a predicate to only display objects marked as favourite.

Cheers, Rog

Rog