A stepwise guideline on developing core data applications for beginners

17 Oct

Image 1Ever since iOS came into existence, developers have been keenly awaiting the core data applications that can enable them to design the perfect data model for their applications. These data applications have served as the best E/R tools and have been effectively used for storage in both OSX and iOS empowered Apple products. Through this blog, I’ll be sharing a refined collection of steps that would allow you to develop core data applications for beginners in the field of iOS app development. So, let’s get going!

A closer look at the Basic Architecture

Image 3Even iPhone Application Development Company in India manage the core data which is being organized into NSManagedObjects that correspond to tables used in the SQLite database. These objects are further broken down into entities that can be associated with a table included within the database. Entities can further include Attributes along with a “Select” operation that can be performed using the NSFetchedManagedObject with the help of Predicates.

The list of code samples that I would be including in this guideline are:

Image 2

And now, the steps involved with the process of developing the core data applications:

  • NSFetchedManagedObject
  • NSManagedObjectContext

  • NSManagedObjectModel

  • NSManagedObject

Step 1- Create a new project

Here, I’ll be using the Utility application template with the Core data enabled. Start off by naming the project.

Step 2- Now, create the Core Data Schema

After having created the project, you’ll find an auto-generated file with the extension as “xcdatamodeld”. This is the core data schema file where you’ll be defining the attributes, entities, relationships and predicates. Start with selecting the Entity node and clicking on the “Add Entity” button. Here, I’ll create two entities viz: Continent and Country. After this, click on the “Add Attribute” button for a specific entity and add an attribute name of string data type. Lastly, add the relationship for each entity. For example, the entity ‘Continent’ can have a relationship name as ‘continents’ with the destination as the ‘Country’ entity.

Step 3- Create the Input screen

As per the third step, open the storyboard file and add two labels, two text fields and a button. Now, with the storyboard file open, opt for clicking on the Assistant Editor for opening the related header file. Next, create IBOutlets for each of the two text fields using the left mouse button. Finally, click on the “Connect” button to add the code, followed by creating the connection. Repeat the process for the second text field as well. Also, for the single button, repeat the process but just change the connection type to “IBAction”.

Step 4- Add the input logic

Now, add the below mentioned code to the SaveData method:

– (IBAction)saveData:(id)sender {
NSManagedObjectContext *cxt = [self managedObjectContext];
NSManagedObject *newContinent = [NSEntityDescription insertNewObjectForEntityForName:@”Continent” inManagedObjectContext:cxt];
[newContinent setValue:self.continentNameFld.text forKey:@”name”];
_continentNameFld.text = @””;

NSManagedObject *newCountry = [NSEntityDescription insertNewObjectForEntityForName:@”Country” inManagedObjectContext:cxt];
[newCountry setValue:self.countryNameFld.text forKey:@”name”];
_countryNameFld.text = @””;

NSError *err;
if (![cxt save:&err]) {
NSLog(@”An error has occured: %@”, [err localizedDescription]);
}

}

Step 5- Test the application

In order to test the developed app you may opt to Hire iPhone App Developer or simply click on the run button and launch the iOS5 simulator. Try testing the app functionality by entering a continent and country in the appropriate fields, followed by clicking on the ‘Save’ button. Keep a check over the log to see if any errors crop up. If no errors are detected, it shows that the app is functioning accurately.

Final Words

Novice web developers find working with core data applications very simple. I’m sure the details covered above would assist you in building a brilliant core data app for building outstanding web solutions.

NOW READ: iPhone Jailbreaking – Why you shouldn’t go for it?

Leave a comment