Core Data: Apple's API for Persisting Data on Mac OS X

Core Data: Apple's API for Persisting Data on Mac OS X

Language: English

Pages: 256

ISBN: 1934356328

Format: PDF / Kindle (mobi) / ePub


Whether you are targeting Mac OS X or the iPhone, at some point your Cocoa application is probably going to need to persist data. You could struggle with SQLite, generate XML, or create your own binary format. Or, you can save time and energy by taking advantage of Apple's Core Data API instead.

Core Data makes it easy for you to work with object graphs and to persist data-but there are plenty of pitfalls and issues to watch out for. This book shows you everything from versioning to integrating with Quick Look, Sync Services, and Spotlight. You'll see how to boost performance and work in multithreaded applications. You'll work with Core Data on both the desktop and the iPhone.

By the end of Core Data, you'll have built a full-featured application, gained a complete understanding of Core Data, and learned how to integrate your application into OS X.

As an extra bonus, you'll see numerous recipes that are useful in unusual situations, or even in places where you wouldn't have thought to use the Core Data API before. It will become another indispensable tool in your kit.

 

 

 

 

 

 

 

 

 

 

 

 

 

NSDateFormatter objects to show date and time information. To add an NSFormatter to a field (either a column or a text field), select it in the library palette, and drag it onto the interface element. Once it is in place, you can configure its details in the Attributes inspector, as shown in Figure 3.3, on the next page. The Attributes inspector will allow you to configure exactly how the data is presented to the user. In addition to properly displaying number and date data, the NSFormatter

on property loading while keeping the -resultType as NSManagedObjectIDResultType. This is often referred to as warming up the cache. Loaded As a Fault The next smallest amount of data that we can retrieve is referred to as a faulted NSManagedObject. What this means is that the NSFetchRequest returns an NSArray of NSManagedObject objects, but those objects contain only the NSManagedObjectID. All the properties and relationships Report erratum Prepared exclusively for Robert Walsh this copy is

our Info.plist file: Download Spotlight/Info.plist UTExportedTypeDeclarations UTTypeConformsTo public.data public.content UTTypeDescription 2. It should be noted that bundle identifiers are in fact UTIs themselves. Report erratum Prepared exclusively for Robert Walsh this copy is (P1.0 printing, September 2009) 124 Download at WoweBook.Com I NTEGRATING WITH S POTLIGHT 125 Grokking

targeted, we could have as little as 20MB of memory to work with. This is drastically different from the modern desktop that measures memory in gigabytes! Therefore, Core Data, to be a good citizen on this much smaller device, must handle memory differently. The best way to handle memory management is to let someone else do it. Fortunately, Apple has stepped up to the plate and done most of the heavy lifting for us. As we will discuss in depth in Section 10.3, Using the

features, although useful, will detract from our focus. Adding Objects to the xib The first part of the user interface we will work on is the objects in the xib file. As with most applications, we need to add the AppDelegate to the xib so that it both will be instantiated on startup and will be properly linked into the application itself. Add the AppDelegate Upon opening MainMenu.xib and depending on the whims of the templates within Xcode, the AppDelegate may already be in the xib file. If it

Download sample

Download