background preloader

CoreData

Facebook Twitter

Cocoa Dev Central: Core Data Class Overview. The Core Data framework provides a lot of new functionality to Cocoa developers, but manages to do so without creating an immense class hierarchy. There are approximately a dozen key classes, which are divided into Model, Runtime and Query classes in this document. written / illustrated by Scott Stevenson The Managed Object Model contains a detailed description of an application's data types.

The Model contains Entities, Properties and Fetch Requests. The Managed Object Context is where the magic really happens. Conventional Cocoa applications usually have a top-down tree of data objects that make up the model. You create a blueprint of this network using Core Data's model classes, which all revolve around the Managed Object Model. Key Model Classes Many of the model classes end in "Description". The Managed Object Model is a detailed outline of an application's data types. The Model is made up of Entities, which have Properties. By default, each Entity is mapped to NSManagedObject. Adding iTunes-style search to your Core Data application. iTunes has a very neat way of searching your library, where it takes each word in your search and tries to find that word in multiple fields. For example, you can search for “yesterday beatles” and it will match “yesterday” in the Name field and “beatles” in the Artist field.

The basic predicate binding for NSSearchField provided by Interface Builder is not complex enough to archive this kind of search. I need to build the predicate dynamically since I can’t assume what field the user is trying to search and that each additional word should filter the list further – just like iTunes. Here is how to go about adding iTunes-style searching. In my application I have a simple Core Data model with one entity (song) and 3 attributes (name, album and artist). Add the following to iTunesFilter_AppDelegate.h: and.

Tutorial: Cocoa Bindings and Value Transformers. In Cocoa bindings value transformers provide a way to take a bound object and produce another object based on the properties of the object passed in. In this tutorial we'll go over how to setup the relevant bindings in a Cocoa/Core Data project, hook up some controls and based on values that get set within our objects have a status icon set and displayed within the GUI of our application. Value Transformers A value transformer is nothing more than a piece of code that receives an object and based on a property of that object returns another object (or the modified original) that posses some other attribute we wish to use in our application (Figure 1). You might be thinking, "If I can create this object in the first place, why do I need a Value Transformer? " Good question.

Figure 1. Project Setup The starting code for the project is available here. Figure 2. Open the file MainMenu.nib (Figure 3). Figure 3. The buttons and tables are connected in the following manner: Figure 4. Figure 5. We are Offline. The journal of Apple technology. Volume Number: 21 (2005) Issue Number: 11 Column Tag: Programming by Jeff LaMarche In the previous two Core Data articles, we discussed how to create a data model and how to create, delete, and edit data instances both directly from the user interface and programmatically.

Those two articles covered most of what you'll need to do with your application data models. Most. But not all. In the prior articles, all instances of data that we worked with were ones that we created, or else were ones that the user took some action upon, so we never had to worry about what piece of data we were going to work with. Now, certainly, you could create an NSArrayController in Interface Builder to represent all the instances of a particular entity type and then manually loop through the items it manages to look for the instances that meet your criteria, but that would be inefficient and involve a lot of unnecessary work. Fetch Requests. Predicate Programming Guide: Using Predicates. This document describes in general how you use predicates, and how the use of predicates may influence the structure of your application data.

Predicate Programming Guide: Using Predicates

Evaluating Predicates To evaluate a predicate, you use the NSPredicate method evaluateWithObject: and pass in the object against which the predicate will be evaluated. The method returns a Boolean value—in the following example, the result is YES. You can use predicates with any class of object, but the class must support key-value coding for the keys you want to use in a predicate. Using Predicates with Arrays NSArray and NSMutableArray provide methods to filter array contents. Home - SQLCipher - Open Source Full Database Encryption for SQLite. Chris Miles: Core Data debugging with SQLite. Testing Core Data with very big hierarchical data sets. The test data My test data will be a three-tier hierarchy. This arrangement reflects data where containment of one set in another is important. It also creates a situation where graph traversal, searching and containment testing can be performed in more than one way, with no approach being obviously better — leading to a desire for performance testing.

The journal of Apple technology. Volume Number: 22 (2006) Issue Number: 2 Column Tag: Programming by Jeff LaMarche In the last Core Data article we talked about creating Fetch Requests programmatically using format strings and predicates. Using format strings to create Fetch Requests is a little bit inelegant, although it does give you a tremendous amount of flexibility. For your day-to-day, run-of-the-mill data fetching needs there is an easier way that gets those format strings out of your compiled code. You can create Fetch Requests right in your data model. Introduction. CoreData.