Projects

Ticket #252 (closed enhancement: fixed)

Opened 3 years ago

Last modified 22 months ago

Support key-value observing via the attr_accessor family of methods

Reported by: jvoorhis@… Owned by: lsansonetti@…
Priority: minor Milestone: MacRuby 0.6
Component: MacRuby Keywords: key-value observing, attr_accessor
Cc:

Description

As per the email thread at  http://lists.macosforge.org/pipermail/macruby-devel/2009-May/001705.html, extend attr_accessor and attr_writer to support key-value observing via setter methods.

Example:

class Notifier

attr_writer :value

end

Notifier#value= could be implemented in terms of Notifier#setValue so observers of Notifier receive notification when the value is changed.

Change History

Changed 22 months ago by martinlagardette@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.6

It is now supported with MacRuby. You can check with the nightlies.

However, please be aware that for notifications to work as expected, you will have to call #framework at least once:

# /tmp/kvn.rb

framework 'Foundation'

class Notifier
  attr_accessor :value
end
class Observer
  def observeValueForKeyPath(path, ofObject:object, change:change, context:context) puts change end
end

n = Notifier.new
n.addObserver(Observer.new, forKeyPath:'value', options:0, context:nil)
n.value = 42
n.setValue 42
$> macruby /tmp/kvn.rb 
{"kind"=>1}
{"kind"=>1}
$>

Changed 22 months ago by lsansonetti@…

It was fixed in r r3915.

Note: See TracTickets for help on using tickets.