From: Jonathan P. <jp...@dc...> - 2005-11-08 23:51:56
|
On 8 Nov 2005, at 21:52, Rupert BARROW wrote: >> >> self.addRubyMethod_withType("#{key}".to_sym, >> "@4@8:12") >> self.addRubyMethod_withType("# >> {set_key}:".to_sym, "@4@8:12@16") > > I tried this; here is the result : > > 2005-11-08 22:42:32.463 SimpleStickies[1306] KVO autonotifying only > supports -set<Key>: methods that return void. Autonotifying will > not be done for invocations of -[Note setText:]. > > Same error is produced for each atribute. > What is the syntax of the second parameter to > 'addRubyMethod_withType' ? It does not seem to acknowledge that > 'void' is returned, although the initial @ is preceded by nothing > (no type). The second argument is a type encoding [1] (see also the objc_method documentation in [2]). It consists of a type code followed by (I think) some sort of stack offset. The "Special Considerations" section in [2] indicates that these are ignored, so you can probably get away with leaving them out. The value I gave before for the setter method is incorrect - it declares an 'id' type return value, when it should be void. Try using this instead: "v@:@". This means, from left to right, v="void", @="id self", :="SEL _cmd", @="id value". Notice how self and selector must be explicitly mentioned. [1] http://developer.apple.com/documentation/Cocoa/Conceptual/ ObjectiveC/RuntimeOverview/chapter_5_section_6.html [2] http://developer.apple.com/documentation/Cocoa/Reference/ ObjCRuntimeRef/ObjCRuntimeRef/chapter_1.4_section_2.html > By the way, why define "#{key}" (without ':') and "# > {set_key}:" (with ':') ? [sorry for silly newbies' questions] Don't worry, it's not obvious. The first argument is the name of the Objective C method to define. A method with no ':' takes no arguments (the getter), whereas the single : indicates that an argument follows it (for the setter, it's the value to set). What we're effectively doing is programmatically making these Objective C class definitions for our Ruby-defined ObjC class: -(id)key; -(void)setKey:(id)value; Cheers, Jonathan |