views:

52

answers:

2

I'm trying to add Core Data to an app that loads news form of an RSS feed so I can store articles offline. I am using ASIHTTP to load the data off of the internet as XML.

I'd like to store the articles in Core Data so I have them the next time I start. My AppDelegate_shared already is set up for Core Data, based on the template, but I'm not sure where to add all the rest of the code.

I found a tutorial by Ray Wenderlich, but it only confuses me. His tutorial assumes that there is a single App Delegate file, not three, as created by the Universal App templates.

  • Where in my three AppDelegate files (the shared, iPhone and iPad specific) does my core data article entry code go?

  • Are there any tutorials that deal with Core Data with the newer app template setup (3 delegate files)?

  • How do I read out my Core Data into a UITableView?

+2  A: 

the core-data stuff belongs to the shared appdelegate. because the other two appdelegates are just subclasses of the shared one.

why not create a new universal project with coredata and look how it's done? and to see how the data is feed into a tableview, you could create a navigation-based project with coredata and look how it's done inthere.

fluchtpunkt
+1  A: 

The Core Data stack only needs to be created in one shared location at startup. You can still have three different application delegates, as long as all three call the same setup routine. This could be done by making all three application delegates you have be subclasses of one base application delegate which handles this setup.

Another way to approach this might be to create a singleton for managing your Core Data access. See this question for other potential configurations that people have used, as well as the reasons for them.

As far as how to populate a table view with data from a Core Data database, you'll want to use NSFetchedResultsController for that. It makes displaying and updating table views simple on iOS. Jeff LaMarche has some good template code for dealing with this, and the sample applications generated when creating a new navigation-based Core Data iPhone application show this in action.

Finally, I taught a class on Core Data last semester (and finished another one last night), for which the course notes are available here and the video can be downloaded from iTunes U.

Brad Larson
Downloaded the video. I plan to watch later. I got other things to work on now.
Moshe
Nice video. I started watching it. About 35 minutes in, the audio changes. (Can I get a copy of your singleton?)
Moshe
@Moshe - Yeah, the batteries ran out on my wireless mike for a bit there. We caught it after a few minutes, so the audio goes back to normal after that. Code for a Core Data singleton can be found in the SimpleCoreData example that I link to in the class notes for that session.
Brad Larson
@Brad - Your course is a winner. I've downloaded the entire thing from iTunes U. Thanks and keep up the great work!
Moshe