[MacRuby-devel] Key-value observing

Jeremy Voorhis jvoorhis at gmail.com
Wed May 13 13:31:34 PDT 2009


I've created a ticket at https://www.macruby.org/trac/ticket/252. I
might be wrong as I am still grokking the Objective-C runtime, but it
seems to me that this should be easy to implement if attr_accessor and
attr_writer generate the setKey: method first and then implement #key=
in terms of setKey:. Is there some requirement that key-value setter
methods return void, or is that just by convention?

Best,

Jeremy

On Wed, May 13, 2009 at 12:00 PM, Laurent Sansonetti
<lsansonetti at apple.com> wrote:
> Hi Jeremy,
>
> That's a pretty good idea! Could you file a bug on the tracker so that we do
> not forget about it?
>
> Thanks,
> Laurent
>
> On May 12, 2009, at 10:18 AM, Jeremy Voorhis wrote:
>
>> Hello,
>>
>> I've been learning Cocoa, Objective-C and macruby in tandem and I was
>> just wondering, are there any plans to integrate the key-value
>> observing protocol with the attr_accessor family of methods? With a
>> little experimentation, I found KVO is definitely possible with
>> macruby, but the syntax is less than ideal (transcript made with the
>> 0.4 release).
>>
>> ~ % macirb
>>>>
>>>> class Notifier
>>>>  attr_accessor :value
>>>> end
>>
>> => nil
>>>>
>>>> class Observer
>>>>  def observeValueForKeyPath(path, ofObject:object, change:change,
>>>> context:context) puts change end
>>>> end
>>
>> => nil
>>>>
>>>> n = Notifier.new
>>
>> => #<Notifier:0x8005e91a0>
>>>>
>>>> n.addObserver(Observer.new, forKeyPath:'value', options:0, context:nil)
>>
>> => nil
>>>>
>>>> n.value = 42
>>
>> => 42
>>>>
>>>> n.setValue 42
>>
>> {"kind"=>1}
>> => nil
>>
>> Best,
>>
>> Jeremy Voorhis
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>


More information about the MacRuby-devel mailing list