Lesson 6. This will look at utilising the core data available within the iPhone. This allows the data to be stored and accessed via an on-phone database, similar to sqllite. In order to describe the core data functionality we will start a new project that includes the in built framework within XCode. We will then combine our new project with some of the functionality we introduced in the previous tutorials to achieve a working, if simple, App.
In the XCode file menu select New Project and the Navigation-based Application. You should notice an option on the screen for you to select “Use Core Data for storage“. Tick the box adjacent to this, select Choose and give your new project a suitable name. As before select Build and Run to see what the template gives you. You should see a table view with Edit and + options on the top navigation bar.
You should also notice that when you look at the files generated for the project there is now a
Before we make any changes to the code we will create our data model ormanaged object model. You can create the model programmatically, or use the Xcode modelling tool to create the model graphically. We will use the XCode tool. There are a number of ways you can add data into the model depending on your personal preference regarding menu options versus mouse clicks. Only one will be discussed here.
Now we will generate the files from our data. Selecting the Title entity choose File > New File from the XCode menu. Managed Object Class should be selected already for you. Select Next. Ensure you are happy with the location and targets. Select Next again and then Finish.
You should now have a News.h and News.m file created within your project. With the properties declared and implemented asdynamic. There is no need for the properties to be Synthesized as the core data will generate the getter and setter methods at runtime. Equally the core data will manage the memory for the data so there is no need to perform the dealloc method for the title and description.
Generating the Title class updated the model as well so you need to make sure you save the model file.
Now we will use the new class. Import the header file in RootViewController.m
In order to read and parse the news data we need to add the reader and parser files we used in the previous tutorial.