Automatic Reference Counting

In the Cocoa world, the big news from WWDC is the advent of Automatic Reference Counting, or ARC. The only real documentation for the system is an unlinked reference page on the Clang website, but as Clang is open source and the implementation’s in the latest builds now, that counts as public information.

The Cocoa frameworks have long used a reference-count-based system, but as of Mac OS X v10.5, Apple added optional garbage collection. As with most GC systems, you can mark certain references as __weak (which automatically become nil when their target is collected), and the actual collection of…

Scripting Bridge

Recently I had occasion to deal with the Finder, beyond what NSFileManager or NSWorkspace could handle. Now, the easy way to do this is through AppleScript, and Cocoa does provide a way to run AppleScripts (NSAppleScript). The trouble is, (a) NSAppleScript is slow and only runs on the main thread, and (b) you can’t pass input easily.

AppleScript is built on Apple events, a mid-to-high-level form of interprocess communication that’s been around since System 7. Apple events can be constructed and sent off using either pure C code (what’s now part of the CoreServices framework) or the Objective-C wrapper, NSAppleEventDescriptor,…

Safer Plugin Categories

Why did I miss last week’s post? To test this!

A few posts back I suggested the use of a category’s +load method as a way to safely swizzle methods in a plugin. What do you do, though, if the same category is going to be loaded twice?

The established behavior of categories, of course is that the last one loaded “wins”.

The behavior of classes, however, is that the first one loaded wins.

That is, if a bundle defines a class with the same name as an existing class, it is not loaded. [bundle principalClass] returns the existing…