From: Rupert B. <rup...@fr...> - 2005-11-08 21:53:05
|
Le 7 nov. 05 =C3=A0 21:29, Jonathan Paisley a =C3=A9crit : > It might be possible to resolve the problem, by defining the =20 > methods in question in Objective C land. There is a special =20 > RubyCocoa method to help you do this. Take a look at the =20 > kvc_array_accessor method declared in oc_import.rb. It uses =20 > addRubyMethod_withType to add a real ObjC method that calls through =20= > to a Ruby method. So you'd convert your kvc_wrapper_representation =20 > to look something like (untested): > > def kvc_wrapper_representation(*keys) > keys.each do |key| > set_key =3D "set" + key > set_key[3..3] =3D set_key[3..3].upcase > class_eval <<-=20 > EOE_KVC_WRAPPER_REPRESENTATION,__FILE__,__LINE__+1 > def #{key} > @_representation.valueForKey("#{key}") > end > def #{key}=3D(val) > self.willChangeValueForKey("#{key}") > @_representation.setValue_forKey(val, "#=20 > {key}") > self.didChangeValueForKey("#{key}") > end > def #{set_key}(val); self.#{key}=3D val; end > EOE_KVC_WRAPPER_REPRESENTATION > self.addRubyMethod_withType("#{key}".to_sym, =20 > "@4@8:12") > self.addRubyMethod_withType("#=20 > {set_key}:".to_sym, "@4@8:12@16") > end > end I tried this; here is the result : 2005-11-08 22:42:32.463 SimpleStickies[1306] KVO autonotifying only =20 supports -set<Key>: methods that return void. Autonotifying will not =20= be done for invocations of -[Note setText:]. Same error is produced for each atribute. What is the syntax of the second parameter to =20 'addRubyMethod_withType' ? It does not seem to acknowledge that =20 'void' is returned, although the initial @ is preceded by nothing (no =20= type). By the way, why define "#{key}" (without ':') and "#{set_key}:" (with =20= ':') ? [sorry for silly newbies' questions] > Having thought about this a bit more, it may be cleaner to =20 > 'improve' the implementation of kvc_reader and kvc_writer to define =20= > these methods and call through to the appropriate ruby setter/=20 > getter. Then you'd implement the delegation to @_representation in =20 > a normal ruby accessor. For the moment, I will leave that to the experts :-) > Hope that makes some sense :) Thanks for you help. Rup |