[MacRuby-devel] Using a context with addObserver
Dave Baldwin
dave.baldwin at dsl.pipex.com
Mon May 17 02:25:14 PDT 2010
Digging a bit more I think a solution to my own questions is:
On 13 May 2010, at 14:33, Dave Baldwin wrote:
> I am trying to translate code that looks like this:
>
> static NSString *SKTWindowControllerCanvasSizeObservationContext = @"com.apple.SKTWindowController.canvasSize";
>
> and later
>
> [[self document] addObserver:self forKeyPath:SKTDocumentCanvasSizeKey options:NSKeyValueObservingOptionNew context:SKTWindowControllerCanvasSizeObservationContext];
>
> to Ruby:
>
> SKTWindowControllerCanvasSizeObservationContext = "com.apple.SKTWindowController.canvasSize"
SKTWindowControllerCanvasSizeObservationContext = Pointer.new(:char)
as all we are after is a unique value. I still don't understand why the original version wasn't acceptable as the documentation says the context argument can be a C pointer or an object reference. Anyhow, this has got me past this point but I have still to prove the final result when it is used by the observer.
> document.addObserver(self, forKeyPath: SKTDocumentCanvasSizeKey,
> options: NSKeyValueObservingOptionNew,
> context:SKTWindowControllerCanvasSizeObservationContext)
>
> but when it runs I get this error:
>
> expected instance of Pointer, got `"com.apple.SKTWindowController.canvasSize"' (String) (TypeError)
>
> How do I get the a pointer to the context string? All the examples I have found for the Pointer class seem to expect an objective C routing to fill it in.
>
> Thanks,
>
> Dave.
>
>
Dave.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100517/84b6b997/attachment.html>
More information about the MacRuby-devel
mailing list