Hampton Lintorn Catlin
Hampton Catlin is the co-founder and CEO of Wordset, an online collaborative dictionary, and rarebit. He is also the inventor of Sass, Haml, and m.wikipedia.org . He's the founder of the libsass project and the author of "The Pragmatic Guide to Sass." He was formerly mobile lead at the Wikimedia Foundation and CTO of Moovweb, helping large companies build better interfaces.
Also, my husband, Michael Lintorn Catlin, has a blog you should checkout if you want to follow what we're up to, non-professionally.
Macruby and Delegate Interfaces
No one can stop me from writing so many damn blogposts about macruby. I’m doing it because no one else out there seems to have any references on these things. So, if these articles have helped you out, just let me know in the comments.
In obj-c we define interfaces called “Delegates” that receive the actions of some other object. For instance, if you have an NSTableView (or UITableView), you can wire it up to a NSViewController that can optionally say “Hey, I can be a delegate for a table view”. It might look like this in obj-c.
@interface SearchViewController : UIViewController
In this obj-c example, we have a class “SearchViewController” that extends “UIViewController”. Oh, by the way, “UI” prefixed things tend to be iOS interfaces and “NS” prefix means cocoa (os x). But, they are extremely similar and it doesn’t change the point here. Within the ”<” and ”>” we list the interfaces that we are declaring. Its basically saying “I’d be happy to receive actions as these types of delegates.” Using these delegates means you can pack a lot of interactivity into your application and when we are doing macruby development, we really need to have these guys on our team.
So! How do we make this work in macruby? Well, the weird answer (to me at least) is magically. Just define a macruby class!
class SearchViewController < NSViewController def tableView(table_view, setObjectValue:value, forTableColumn:column, row:row_index) doc = @documents[row_index] doc.name = value end end
And, wire up any delegations you want in the Interface Builder…. it just works.
I’m not sure what black magic, but to someone with obj-c experience it seems a bit creepy. So, read this blogpost and take heart… JUST WIRE IT UP.