0

In this tutorial for sheet programming in cocoa, I am told to invoke the following method:

[[alert beginSheetModalForWindow:[searchField window] 
    modalDelegate:self 
    didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) 
    contextInfo:nil];

I have written this as follows in ruby,

alert.beginSheetModalForWindow(self.window, 
    modalDelegate:self,
    didEndSelector: :alertDidEnd,
    contextInfo:nil)

Of course, the didEndSelector part is wrong. Later in my code I have a method alertDidEnd, which takes returnCode and contextInfo as arguments. When I looked at self.methods I noticed that the method is listed as alertDidEnd:returnCode:contextInfo:. In the sample code above an '@' is used to mark the selector. This is accomplished in Macruby with a symbol, but in this case the symbol would contain colons, which is not allowed. How should I represent this method name as a symbol? I wasn't able to find this information on my own, where should I have looked that I didn't?

Thanks!

Ziggy
  • 21,845
  • 28
  • 75
  • 104

2 Answers2

2

As noted in the MacRuby docs, symbols are bridged with selectors. So you'd do:

alert.beginSheetModalForWindow(self.window, 
    modalDelegate:self,
    didEndSelector: :'alertDidEnd:returnCode:contextInfo:',
    contextInfo:nil)
Chuck
  • 234,037
  • 30
  • 302
  • 389
  • Hmm... still doesn't call the method though. Does the symbol need to include the entire footprint? When I puts self.methods.sort I noticed that the alertDidEnd method is actually called alertDidEnd:returnCode:contextInfo: . That has a bunch of colons in it: can I still include this as a symbol? – Ziggy Jul 18 '11 at 23:29
  • @Ziggy: Yes, it needs the entire selector. I didn't notice the selector itself was different in the two snippets. I've fixed the answer now. – Chuck Jul 18 '11 at 23:35
  • This seems to be the right syntax, but the method isn't being called. You have answered my question, but it seems there is something else broken somewhere. Back to work! – Ziggy Jul 18 '11 at 23:41
1

Have you tried using a Symbol? It seems to work in RubyCocoa.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347