Setting up Unit Testing in Xcode 3.1

Xcode includes OCUnit, so you don’t need to get a copy. But, you might want to take a look at their website ( for information and tutorials on how OCUnit is intended to be used.

If you are planning on doing Test Driven Development (TDD) you may also want to get the following packages:

Other good articles on Xcode Unit Testing that I came across:

By reading through the documents references above I was able to get OCUnit up and running for one of my projects. It took a bit of experimentation, but in the end it looks like OCUnit will work just fine for doing TDD in Xcode with Objective-C. Anyone wanting to try out TDD should give it a try. The benefits for your project are significant. Go for it!


Method Swizzling in Safari on Mac OS X

Recently I have been working on an extension for the Safari web browser. The biggest challenge when developing an extension for Safari is determining how to hook your code into Most browsers these days provide hooks to allow development of extensions, but Safari does not.

A technique that many people use to add functionality to Safari (and other Cocoa applications) is called Method Swizzling. If you want to learn more about this technique there is a terrific article explaining all the details on the CocoaDev site.

When applying the method swizzling technique you may find that the linker complains about unresolved classes and won’t link your bundle. This issue usually crops up when you try swizzling a method that is in a class you learned about by running class-dump or by using FScript. If you run into this problem bring up the project properties in Xcode and add -undefined dynamic_lookup to the Other Linker Flags section.

Without this extra flag your plug-in will not link, and you will be stuck in the mud! Thanks to Aaron Harnly, author of Letterbox, for pointing this out to me in an e-mail exchange.

Generating a GDB Log File for Xcode Debug Sessions

If you would like to capture a log of everything that GDB displays during a debugging session you can do the following:

$ defaults write PBXGDBDebuggerLogToFile YES

The statement above will turn on logging to a file. Now, you need to set the filename for the debugger output file. Use the following statement to accomplish that.

$ defaults write PBXGDBDebuggerLogFileName /tmp/gdboutput.log

This will create a file in the /tmp directory called gdboutput.log, containing everything you see in the GDB command window during your debugging session.

Both of these commands need to be typed into a window. You only need to do this once, as your machine will remember the settings.