Tiger Time
Volume Number: 21 (2005)
Issue Number: 5
Column Tag: Programming
Tips From Big Nerd Ranch
Tiger Time
by Aaron Hillegass, Chris Campbell, and Marquis Logan
For this special Tiger issue, it seems appropriate to pass on a few tips that may help as you move your development efforts to Mac OS X 10.4.
All-In-One
Xcode 2 has several nifty new features, but our absolute favorite is "All-In-One Layout." In previous versions of Xcode, if you had a few projects open and each project had a build panel, a run log, a debugger panel, and an editor window, you were quickly lost in a sea of windows. In Xcode 2, all of these functions can be done in a single window. To experience the pure joy of All-In-One, you must close all your projects and open the General Preferences:
Figure 1.
When you open a project, there will be a segmented controller labeled Page on the left end of the toolbar:
Figure 2.
There are three pages:
The editor page handles editing, project search, and revision management.
The build page handles the building, the build log, and the run log.
The debug page handles debugging.
If you often work with several projects simultaneously, this will make your life a much more pleasant place.
Backwards Compatibility
If only users would update immediately to Tiger, we would not have to worry about backwards compatibility. The most common source of backwards compatibility issues is inadvertent use of new Tiger APIs. This will prevent your application from running on 10.3. There are two good solutions to the problem.
Figure 3.
This will cause the application to link against stub libraries that match the APIs available on 10.3.
Solution 2 (our favorite): Use the "Current Mac OS" SDK to take advantage of all the latest APIs on the current system:
Figure 4.
and set the "Mac OS X Deployment Target" in the target build settings to 10.3:
Figure 5.
This causes the newer APIs to be weak-linked into the application. It requires a little additional work by the developer to check the availability of an API in the code and gracefully handle cases where API is missing (running on an earlier version of the OS).
C function symbols need to be checked if their value is valid:
if (CGContextFillEllipseInRect != NULL)
{
CGContextFillEllipseInRect(context, rect);
} else {
// Older OS version actions
}
Objective-C methods can be detected using -[NSObject respondsToSelector:]
if ([tableView respondsToSelector:@selector(setColumnAutoresizingStyle)])
{
[tableView setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
} else {
// Older OS version actions
}
This is the most powerful solution as it allows the developer to take advantage of the latest features while maintaining the broadest compatibility.
See Apple's documentation on cross development for more details:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_development/index.html
Debugging Bindings
There have been many complaints that bindings are difficult to debug. This is sadly still true, but Apple has begun to make things easier for us. There is now a default NSBindingDebugLogLevel. Set it to 1 to turn on logging. The easiest way is to pass it as an argument on the command-line. Under the Executables group in Xcode, select your application, and look at the info panel. Add the argument -NSBindingDebugLogLevel 1.
Figure 6.
In the short time that we have been using Tiger, we have found it to be a superior platform for developers. It is chock-full of fun new technologies and is even more beautiful than 10.3. Enjoy!
Aaron Hillegass, Chris Campbell, and Marquis Logan