[MacRuby-devel] How to retrieve an observer's context?
lsansonetti at apple.com
Mon Apr 20 13:28:56 PDT 2009
Context arguments in Objective-C are generally void pointers, which
makes them hard to use in Ruby. Also, since we run in Objective-C GC
mode, objects could potentially be collected since contexts do not set
up AFAIK write barriers.
I would recommend to set up an instance variable on your observer
instead (and pass nil as the context).
And later in your observer method, retrieve the ivar.
On Apr 20, 2009, at 8:57 AM, Edward Hynes wrote:
> I'd like to use contexts when registering some observers, but have
> been unable to retrieve them, getting a "can't convert C/Objective-C
> value `0x2822731' of type `v' to Ruby object" instead. The
> following code, for example, will trigger the error
> class Subject
> attr_accessor :abc
> class Observer
> def observeValueForKeyPath keyPath, ofObject:object, change:change,
> subject = Subject.new
> observer = Observer.new
> subject.addObserver observer, forKeyPath:'abc', options:0,
> context:'a context'
> subject.setAbc 'some value'
> Is there a way to retrieve an observation context? Or is there an
> alternative way for observers to distinguish among multiple
> registrations for a given object/keyPath?
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
More information about the MacRuby-devel