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.

504<br />

CHAPTER 26 MAC <strong>OS</strong> X DEVELOPMENT: OBJECTIVE-C<br />

• Create derived properties. For example, you might later decide to derive name from<br />

properties called firstName and lastName.<br />

• Create dependent keys, such that a change to one key triggers change notifications in other<br />

keys.<br />

• Sync keys to other keys using bindings, the zero-code technology that gives Interface<br />

Builder much of its power.<br />

• Bridge properties between Objective-C and other technologies such as Core Data and<br />

AppleScript.<br />

Objective-C 2.0<br />

Apple has long contributed to the usefulness of Objective-C. Apple has done this directly by contributing<br />

to the GNU open source projects that compile, debug, and link Objective-C applications.<br />

They’ve also done this indirectly by providing frameworks such as Cocoa. With <strong>Leopard</strong>, Apple<br />

has finally begun to improve the language itself in an effort known as Objective-C 2.0.<br />

Class Extension<br />

One of the most common uses of Objective-C’s method categories is the creation of private<br />

headers. These define methods that are used by the internal implementation of a class but should<br />

not be called from outside the class.<br />

In a way, this is an abuse of the language. Categories are meant to arrange a class’s implementation<br />

by functionality. Using a category to define private methods creates an artificial<br />

separation in the implementation based on visibility, rather than function.<br />

Class extensions are a new kind of “anonymous” category. Unlike a standard category,<br />

which extends both the interface and the implementation, a class extension extends only the<br />

interface. The implementation remains with the main class. Thus, a public method and closely<br />

related private methods can remain together.<br />

For example, say you had a contrived class whose public interface declared like this:<br />

@interface MyClass : NSObject<br />

- (void)publicMethod;<br />

@end<br />

Within your implementation file (or private header), you would declare the following:<br />

@interface MyClass ()<br />

- (void)privateMethod;<br />

- (void)privateHelper;<br />

@end<br />

Then your implementation would look something like this:<br />

@implementation MyClass<br />

- (void)publicMethod;<br />

{<br />

[self privateMethod];<br />

// ...<br />

}

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

Saved successfully!

Ooh no, something went wrong!