Skip to content

Needs documentation on how to pass an pointer-to-pointer “out parameter” #3

Open
@uranusjr

Description

@uranusjr

It is common in Cocoa API for a method to have an “out parameter”, e.g. an NSError ** parameter that is used to return an error when a call fails.

Taking the deserialisation method in NSJSONSerialization for example, this method

+ (id)JSONObjectWithData:(NSData *)data
                 options:(NSJSONReadingOptions)opt
                   error:(NSError **)error

can be called like this in Objective-C:

NSError *err = nil;
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];

And the equivalent with Rubicon-objc would be

from ctypes import byref, c_void_p

err = c_void_p(0)
obj = NSJSONSerialization.JSONObjectWithData_options_error_(
    data, 0, byref(err),
)

NB: err = None will not work since byref expects a ctypes instance, and does not automatically convert None to a NULL pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions