From: Johan L. <joh...@gm...> - 2009-08-31 17:26:51
|
Okay so this SO-question helped a bit: http://stackoverflow.com/questions/561185/optional-arguments-in-objective-c-2-0 I'm just gonna make two methods instead; one "filename" and another "filenameWithLanguage" or something like that. Sincerely, Johan Lundström joh...@gm... 2009/8/31 Johan Lundström <joh...@gm...>: > What is the rules about optional method arguments in > NSObject-subclasses? I recently upgraded from 0.13.1 to 1.0.0 and this > problem appeared: > > class Subtitle < NSObject > def filename(add_language = false) # notice optional arg here! > # ... > end > end > > When using "Build & Go" from Xcode it crashes immediately with this error: > > [...]/build/Debug/Undertext.app/Contents/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_import.rb:346:in > `_ns_behavior_method_added': Cannot override Objective-C method > 'filename' with Ruby method #filename, they should both have the same > number of arguments. (expected arity 0, got -1) (RuntimeError) > from [...]/build/Debug/Undertext.app/Contents/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_import.rb:684:in > `method_added' > from [...]/build/Debug/Undertext.app/Contents/Resources/Subtitle.rb:25 > from [...]/build/Debug/Undertext.app/Contents/Resources/rb_main.rb:17:in > `require' > from [...]/build/Debug/Undertext.app/Contents/Resources/rb_main.rb:17:in > `rb_main_init' > from [...]/build/Debug/Undertext.app/Contents/Resources/rb_main.rb:16:in `each' > from [...]/build/Debug/Undertext.app/Contents/Resources/rb_main.rb:16:in > `rb_main_init' > from [...]/build/Debug/Undertext.app/Contents/Resources/rb_main.rb:22 > > When removing the argument or removing the default-value (ie. false) I > get no error. My guess this is expected behaviour, but what is the > exact rules and why? > > Sincerely, > Johan Lundström > > joh...@gm... > |