Core Data Helper – the final chapter!

I’ve probably written about the Core Data Helper too many times for one blog, but I thought just to finish it off I’d write one more article with a good solid downloadable project to demonstrate the use of Core Data Helper.  Basically the helper wraps core data stuff to make accessing it a little tidier… in fact, instead of re-inventing the written wheel (?), why not read about it in the other article HERE and then come back.

So what’s this article all about then?  Well, just below this paragraph is a download link to my project which very basically shows how to use the Core Data Helper.  It also has a useful XML parser for pulling in some default data from an XML file to your Core Data store.  I use this similar format for data which will appear in static lookups and suchlike.  Go download it and take a look….

[download id=”2″ format=”1″ autop=”false”]
(Note: You must be logged in to download the file)

So if you ran the project you’re probably wondering WTF?  Sure, it didn’t appear to do much in the iPhone simulator except show a blank screen.  Correct – all of the magic is happening in the debugger console window.  Here’s essentially what the app is doing….

  • First it uses the DefaultDataParser to read in an XML file (called “presetData.xml”) and it stuffs all that data into my core data store, in an entity called “Movies”. There are only 14 movies, so don’t get too excited.
  • Next, in the HelperDemoAppDelegate.m file I use the core data helper to do various things with my data store.

When you run the app, you should have an output similar to this…

**************************************
** 1. Display original data first   **
**************************************
  28 Days Later (Horror)
  Alien (Thriller)
  American Pie (Comedy)
  Gladiator (Action)
  Labyrinth (Adventure)
  Leon (Action)
  Moulin Rouge (Musical)
  Predator (Action)
  Say Anything (Comedy)
  Spiderman (Action)
  The Goonies (Adventure)
  The Grudge (Horror)
  The Princess bride (Adventure)
  The Thing (Horror)

**************************************
** 2. Count all entities in Movies  **
**************************************
  There are a total of 14 movies in the data store
  This will be a count of all the entries listed above

**************************************
** 3. Display all horror films      **
**************************************
  28 Days Later (Horror)
  The Grudge (Horror)
  The Thing (Horror)

**************************************
** 4. Count all Adventure movies    **
**************************************
  There are a total of 3 adventure movies in the data store
  This example uses a predicate to count specific entities

**************************************
** 5. Delete all action movies      **
**    then show the listing again   **
**************************************
  28 Days Later (Horror)
  Alien (Thriller)
  American Pie (Comedy)
  Labyrinth (Adventure)
  Moulin Rouge (Musical)
  Say Anything (Comedy)
  The Goonies (Adventure)
  The Grudge (Horror)
  The Princess bride (Adventure)
  The Thing (Horror)

**************************************
** 5. Delete all movies and show    **
**    listing again. Should be      **
**    empty below                   **
**************************************

So if you go check the App Delegate file you’ll see the various examples of using the helper.  Clear as mud?  Probably not, but it’ll surely help someone to cut some corners.  If it’s useful to you, please post and let me know.

Leave a Reply