I am working on a project where I have a table view that is currently updated via a web request that returns XML. I implemented
-(int)numberOfRowsInTableView:(NSTableView*)tv
and
-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn*)tableColumn row:(int)row
in my XML parsing class, and have the table updated with the data that is pulled down from the server.
I want to save the data that is pulled down using Core Data, so that the table can be saved/loaded. Then later on application start when the web request is made, it will only add data that is not already present. (The XML is sorted by release date, so later I will check to see which release dates are not loaded up from the Core Data store, and only load newer entries.)
How would I go about implementing this? I am a very new Cocoa developer, but have gone through the entire Hillegass book. Thanks so much.
There are two big pieces that you’re talking about here: parsing XML, and persistence with Core Data.
(1) I have had some success using this wrapper around NSXMLParser to read XML files. I’ve heard of but have not used more recent libraries, but this may provide a starting point for you. The linked article is quite thorough about usage.
(2) The first thing you will want to do with Core Data is create a new data model. From there, you can create an model class (with
@dynamicproperties) to easily interact with your database through Core Data (using things like NSManagedObjectContext and its ilk). You can get a gentle introduction here, or jump in a little further along here.Implementing Core Data is non-trivial, especially for newer developers. I’d encourage you to seek out tutorials on particular topics as they arise.