Popular Tags

Who's online

There are currently 0 users and 78 guests online.

User login

I'm currently working on getting the hang of Core Data, so I'll be updating this as I learn. To start off, I'm reading these links (in order):


With each major release of Mac OS X, Apple has been adding more features to the Cocoa Frameworks that simplify the development process. From the start, everything has been about the Model-View-Controller design paradigm. The first to get implement was the View aspect, in the form of Interface Builder (IB). IB is basically a drag-and-drop interface construction kit. With it, developers can rapidly create professional looking interfaces without having to deal with things like JButtons or JPanels that are so proliferate in Java.

Panther (10.3) introduced things on the controller level: data-specific controllers. These are things such as NSTreeController, NSArrayController, NSDictionaryController, NSViewController, NSWindowController, and so on. These objects provided simple ways to connect stores of information to the interface.

About the same time, Cocoa Bindings came along. Bindings are a fantastic way to get rid of almost all the "glue code" that resides in controller objects. This glue code is what ties the model (the data structure) to the view (the interface). With Bindings, apps suddenly became much lighter and developers could concentrate more on the things that made their apps unique.

In all of this, though, Apple was virtually ignoring the Model layer. The View and Controller components all had their niceties, but the model, which is arguably the most important part of any application, was still left up to the developer to code by hand. To remedy this, Apple introduced Core Data in Tiger (10.4).

What is Core Data?

Core Data is for the Model what Interface Builder is for the View. It's a graphical way to define how data is stored internally and how different kinds of data relate to each other.

To create an application with Core Data, choose File New Project... (N) and select "Core Data Application", "Core Data Document-based Application", or "Core Data Document-based Application with Spotlight Importer".

Choosing one of these options will include all of the necessary code to load your app's data file. If you want to add Core Data support to an existing app, the following code is the basic outline for how to define where Core Data stores your Model:

NSURL *url = [NSURL fileURLWithPath:@"path/to/file.xml"];
NSArray *bundles = [NSArray arrayWithObject:[NSBundle mainBundle]];
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:bundles];
NSPersistentStoreCoordinator *coordinator =
   [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url error:&error];
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: coordinator];

Your rating: None Average: 5 (1 vote)



The site has recently been updated. You may notice some of the following issues:

  • Some URLs no longer work. Please use the search box.
  • File uploads should now be working. If you experience problems, please contact us.