Core iOS Core Architecture Recommendations

I just want to get some pointers on the best way to architect my first Core Data application, as well as the main objects and interactions that I need.

The data is stored remotely, and I will need to access it through HTTP, and it will respond in JSON format. I want to cache this on a device using Core Data. Every day, new data will appear on the server, so I need to access it and update the model accordingly.

Are there any SDK classes that I can use to help me with this, or am I going to drop it?

I guess I look at the model controller that I call to get the data, it will return the cached data of the main data and maybe make a background call to the web service to get the latest data, and then notify the opinion that there are new data. When I receive data from a web service in JSON format - I need to map this to ManagedObjects, adding data to my main context.

+7
source share
3 answers

Thanks dtuckernet, here's what I did - collecting information from a large number of sources, which I think is the best solution. Anyone can criticize (constructively) ....

  • I have my own Core Data stack in CoreDataStack.h (singleton) - not really needed, but it decompresses the delegate class of my application.
  • I have a basic CoreDataBackedTableViewController: UITableViewController
  • Each of my table view screens extends the CoreDataBackedTableViewController and has an ivar for the ModelController class.
  • The ModelController class example has a getData method - (NSFetchedResultsController *), which creates an NSFetchedResultsController (also stores the link) and returns it to the view controller, which also stores it in the CoreDataBackedTableViewController (which listens for updates and edits data). Having a ModelController class allows me to encapsulate data access in order to potentially use 2 different view controllers (possibly iPhone and iPad).
  • In getData - I make an asynchronous call to my backend service. Using delegates for callbacks
  • The backend uses SBJSON for parsing both the NSHttpConnection and the manual skating class HttpService.
  • When the backend returns with data, it calls a delegate to ModelController, which updates the main data, and my fetchedResultsController knows about it and automatically updates my interface! How cool this bit is - on my part there is not much effort. I have to make some discovery if I really downloaded the data before or to avoid duplicates.
  • Ready to flip this for the rest of my application ....

If anyone wants any clarification on any of the steps, just let me know.

+5
source

There are many different plays. Let me make some suggestions:

  • To get data from the server, I would look at ASIHTTPRequest. This is a good solution to manage your HTTP requests (whether you use JSON, XML, etc.). http://allseeing-i.com/ASIHTTPRequest/
  • To translate JSON, I would look at SBJSON. The site has documentation on how to get started: http://code.google.com/p/json-framework/
  • For your overall architecture, I would use a delegate template that completes your calls. In this doing, you must handle the translation of the JSON data into the actual Objective-C classes before the data is passed to the rest of the application.
  • After the data has been parsed and placed into Objective-C objects (and I would like these objects to be subclasses of NSManagedObject associated with your data model catalog), I would save.
  • Then I used NSNotification to inform the necessary perceptions that the data was changed.
+3
source

You absolutely definitely want to use RESTKit . This is a direct connection from the RESTful web service to the master data. Define your data model with the built-in Xcode tool, define a display layer for your web service using RESTKit, and let the library perform a heavy lift. It is wonderful.

+3
source

All Articles