Outline Views with RubyCocoa

Tim Perrett contributed this great example that creates an outline view from Ruby.

You can download a zip file here. Just unpack it and build the Xcode project inside.

It loads the interface pictured above from a nib file (it’s in MainMenu.nib) and includes support for maintaining and growing one of Cocoa’s trickier components, the NSOutlineView.

Looking through the source, you’ll note that Tim took special care to note the return type that Cocoa expects for each of his methods. Since they were all defined by existing protocols, RubyCocoa was able to automatically guess the correct types, but it’s always a good idea to be sure.

To take this example further, try to edit the name of one of the outline elements. Oops! What needs to be changed?

Have fun!

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License.

What do you think of this book? Post your comment or suggestion below!

Comments (2) post
  1. Tim Perrett Sat May 05 10:27:43 +0000 2007

    lol, oops I hadnt noticed that! I’ll have a look at the edit delegate tomorow and fix that ASAP!

    Cheers

    Tim Perrett

  2. Praful Thu Feb 28 16:12:06 +0000 2008

    This is unrelated but I thought I’d ask.

    I am writing a Ruby Cocoa application and wanted to have a worker thread to allow the GUI to remain responsive whilst some background processing occurred. The worker threads needs to update a textview with messages and a progress bar. At the moment I am simply passing a reference to the textview to the worker thread as a closure. The worker thread is happily writing to the textview. From the Cocoa documentation, I thought that only the main thread should (can?) write to the GUI. If so, how can I pass messages from the background thread to the main thread?

    Thanks