Implementing Delegate Functions
I am trying to port StarJour ( http://github.com/lachie/starjour/tree/master ) over to MacRuby and need some assistance with how to override delegate functions for the NSNetServiceBrowser Is there somewhere (tutorial RFTM?) I can use to find this? Christopher Williams President/CEO Iterative Designs LLC http://www.iterativedesigns.com 1818 Library Street: Suite 500 Reston, VA 20190 info[:email] => chris@iterativedesigns.com info[:office] => 703.956.3015 info[:cell] => 703.628.7533 info[:twitter] => voodootikigod ( http://www.twitter.com/voodootikigod )
Hi Chris, On Oct 1, 2008, at 11:17 AM, Chris Williams wrote:
I am trying to port StarJour ( http://github.com/lachie/starjour/tree/master ) over to MacRuby and need some assistance with how to override delegate functions for the NSNetServiceBrowser Is there somewhere (tutorial RFTM?) I can use to find this?
Implementing delegate methods is done the same way you would do it in Objective-C. Example: browser = NSNetServiceBrowser.new delegate = Object.new def delegate.netServiceBrowserWillSearch(browser) puts "search commencing!" end def delegate.netServiceBrowser(browser, didNotSearch:errorInfo) puts "search not successful: #{errorInfo}" end browser.delegate = delegate browser.searchForBrowsableDomain, You could also implement the delegate methods in a separate class and pass a new instance of that class to the setDelegate: method (available as #delegate= too) of the net service browser object. Creating Objective-C selectors from MacRuby is discussed in the "Defining Methods" section of the tutorial: http://www.macruby.org/trac/wiki/MacRubyTutorial HTH, Laurent
participants (2)
-
Chris Williams
-
Laurent Sansonetti