[MacRuby-devel] NSManagedObject being returned in delegate as Pointer

Laurent Sansonetti lsansonetti at apple.com
Tue Dec 30 19:46:53 PST 2008


On Dec 30, 2008, at 7:32 PM, Nic Williams wrote:

> In this code sample: http://gist.github.com/41855 I am getting a
> Pointer instance instead of an NSManagedObject_Recipe instance (from
> Core Data). Subsequently the setValue:forKey: call at the end of the
> delegate/callback method fails.
>
> The top method addImage(sender) launches an NSOpenPanel, which
> delegates to the second/last method
> addImageSheetDidEnd:returnCode:contextInfo: when the panel is closed.
>
> But instead of passing through the NSManagedObject_Recipe instance to
> the contextInfo: recipe value, I am getting a Pointer.
>
> Is this correct? Or how do I get my NSManagedObject_Recipe instance
> from the Pointer. MacRuby src for Pointer class doesn't suggest it has
> any methods for getting the pointed-to thing.
>
>    rb_cPointer = rb_define_class("Pointer", rb_cObject);
>    rb_undef_alloc_func(rb_cPointer);
>    rb_define_singleton_method(rb_cPointer, "new_with_type",
> rb_pointer_new_with_type, 1);
>    rb_define_method(rb_cPointer, "assign", rb_pointer_assign, 1);
>    rb_define_method(rb_cPointer, "[]", rb_pointer_aref, 1);

You can do pointer[0] to dereference it.

A Pointer object can be created from a C array of elements, which is  
why Pointer responds to #[] (so that you can dereference a particular  
slot).

Laurent


More information about the MacRuby-devel mailing list