From: Patrick G. <pge...@wa...> - 2008-05-19 15:07:08
|
> It seems as if RubyCocoa's key-value observing works differently in > some ways than Objective-C's would. Is this intentional? An incomplete > implementation? The real question: is it stable behavior an app can > depend upon? Checking the source of kvc_accessor from oc_import.rb : declaring an accessor with kvc_accessor will call KVO methods in the setter. setValue_forKey calls KVO methods + accessor, which again calls KVO methods, thus the 2 notifications. I don't know if that's correct. def kvc_accessor(*args) kvc_reader(*args) kvc_writer(*args) end def kvc_writer(*args) args.flatten.each do |key| setter = key.to_s + '=' attr_writer(key) unless method_defined?(setter) alias_method kvc_internal_setter(key), setter self.class_eval <<-EOE_KVC_WRITER,__FILE__,__LINE__+1 def #{kvc_setter_wrapper(key)}(value) willChangeValueForKey('#{key.to_s}') send('#{kvc_internal_setter(key)}', value) didChangeValueForKey('#{key.to_s}') end EOE_KVC_WRITER alias_method setter, kvc_setter_wrapper(key) end end |