05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

424<br />

CHAPTER 24 MAC <strong>OS</strong> X DEVELOPMENT: THE APPLICATION FRAMEWORKS<br />

• Specialized collections like character sets, index sets, and pointer arrays<br />

• Data loading—local and networked, synchronous and asynchronous<br />

• Data manipulation, conversion, transformation, and formatting<br />

• XML parsing, editing, and transformation<br />

• System functions like run loops, threads, and timers<br />

• Interprocess communications via pipes, ports, and notifications<br />

• Language services like exceptions, garbage collection, and messaging<br />

It’s not called Foundation for nothing. AppKit and the rest of Cocoa are built on top of<br />

Foundation. This follows the general trend in <strong>Mac</strong> <strong>OS</strong> X development: Apple creates tools, and<br />

then uses those tools to make easy-to-use frameworks. Then, it gives developers the tools as well,<br />

so they can modify or add as they see fit.<br />

Foundation, while extensive, might not seem so different from any other basic library. In<br />

practice, however, Foundation is designed with the same ease of use and snap-together design as<br />

AppKit. The classes try to maintain similar interfaces, so, for example, if you decide to refactor<br />

an array into a set, there’s very little effort involved.<br />

Since the interfaces are predictable, it’s easy to keep Foundation in your head, despite its<br />

breadth. And since it’s written in Objective-C, it’s extremely easy to figure out how to use a<br />

method without having to constantly go back to the documentation.<br />

As with AppKit, Objective-C also makes Foundation classes customizable via subclassing<br />

and categorization (one of the many tricks outlined in the section on Objective-C), so no matter<br />

what you need to do, you’re rarely, if ever, stuck having to roll your own.<br />

Core Data<br />

A lot of people had a lot of reasons why Apple could never transition their architecture from<br />

PowerPC to Intel. Yet, when they did just that, most of those reasons ended up being non-issues.<br />

For example, the fact that the two architectures read bytes of binary code in opposite directions<br />

(the so-called endianness issue) ended up not affecting most developers at all.<br />

The reason is abstraction. By using high-level frameworks like AppKit and Foundation,<br />

developers are protected from implementation details like byte order. The Core Data framework<br />

takes that idea a step further by abstracting applications from even their own data.<br />

Traditionally, the system is ignorant of an application’s objects and what they’re doing.<br />

Whether you’ve got a word processing document, a photo album, or a dungeon-roaming adventurer<br />

in a mystical land beyond time and space, to the system they’re all just ones and zeros. You<br />

can ask the system to write those ones and zeros to disk, and you can ask it to read them back,<br />

but when it comes to interpreting what they mean and how the user’s actions affect them, you’re<br />

on your own.<br />

Core Data establishes a generalized object model. As long as your objects conform to that<br />

model, the system can tell enough about them to handle many aspects of their lives with little or<br />

no intervention on your part. For example, undo and redo, traditionally one of the harder problems<br />

to deal with, is free in Core Data.<br />

One of the first things you learn in system design is how to plan your objects, their structures,<br />

and their relationships in an entity relationship diagram (ERD). Xcode, Apple’s integrated<br />

development environment, even provides a graphical ERD tool, as shown in Figure 24-3. With<br />

Core Data, drawing an ERD doesn’t just plan your objects, it also implements them. You can<br />

even drag entities out of the ERD into Interface Builder, and Core Data will generate your entire<br />

user interface!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!