|
From: Rupert B. <rup...@fr...> - 2005-11-10 06:04:20
|
Le 9 nov. 05 =C3=A0 00:51, Jonathan Paisley a =C3=A9crit :
> On 8 Nov 2005, at 21:52, Rupert BARROW wrote:
>>>
>>> self.addRubyMethod_withType("#{key}".to_sym, =20
>>> "@4@8:12")
>>> self.addRubyMethod_withType("#=20
>>> {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 =20
>> only supports -set<Key>: methods that return void. Autonotifying =20
>> 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 =20
>> 'addRubyMethod_withType' ? It does not seem to acknowledge that =20
>> 'void' is returned, although the initial @ is preceded by nothing =20
>> (no type).
>
> The second argument is a type encoding [1] (see also the =20
> objc_method documentation in [2]). It consists of a type code =20
> followed by (I think) some sort of stack offset. The "Special =20
> Considerations" section in [2] indicates that these are ignored, so =20=
> you can probably get away with leaving them out.
>
> The value I gave before for the setter method is incorrect - it =20
> declares an 'id' type return value, when it should be void. Try =20
> using this instead: "v@:@". This means, from left to right, =20
> v=3D"void", @=3D"id self", :=3D"SEL _cmd", @=3D"id value". Notice how =
self =20
> and selector must be explicitly mentioned.
Thanks, "v@:@" worked well : we are making progress.
I am now stuck on encoding problems : the two methods 'initWithCoder=20
(coder)' and 'encodeWithCoder(coder)' of the NSCoding protocol are =20
defined like this :
def initWithCoder(coder)
self.super_init
if (coder.allowsKeyedCoding)
@_representation =3D =
coder.decodeObjectForKey("representation")
else
@_representation =3D coder.decodeObject;
end
return self
end
=09
def encodeWithCoder(coder)
if (coder.allowsKeyedCoding)
coder.encodeObject_forKey(@_representation, =
"representation")
else
coder.encodeObject(@_representation);
end
return
end
However, the program comes up with the following error, which is =20
generated within 'encodeWithCoder' :
Exception occured while syncing: *** -encodeObject:forKey: only =20
defined for abstract class. Define -[NSArchiver encodeObject:forKey:]!
Googling for this shows that it is quite a common error when things =20
have not been programmed correctly (eg testing for =20
'allowsKeyedCoding'), but as I have translated the tutorial over from =20=
Objective C ...
... either something is wrong in the code of these two methods, above =20=
(Objective-C says 'self=3Dsuper.init' in initWithCoder, but Ruby =20
refuses 'self=3Dsuper_init') ...
... or we have another 'Ruby vs. Objective-C' context/visibility =20
problem.
I tried adding the following
self.addRubyMethod_withType(:initWithCoder, "@:@")
self.addRubyMethod_withType(:encodeWithCoder, "v@:@")
which changed nothing.
Any ideas ?
Rup
|