2

The following question describes a situation where a python function call to an Objective-C function that requires a variable passed by reference:

Can't call methods on objects in pyObjC

However, the question was posted in 2012 and the accepted answer no longer seems to work. How can we pass the NSError object to the function and get a returned value?

My function call is part of a Framework that I cannot edit, so I have been tasked with finding a way to make it work.

C1pher
  • 1,933
  • 6
  • 33
  • 52
  • Does this help? https://stackoverflow.com/questions/4353403/pyobjc-and-returning-out-parameters-i-e-nserror it seems even older, so maybe not.. – Dale Jul 29 '17 at 00:23

1 Answers1

2

It appears that I attempted to access my custom framework incorrectly. Originally, I accessed the framework by loading a CustomFrameworkBundle:

CustomFrameworkBundle = objc.loadBundle("Custom", globals(), bundle_path=objc.pathForFramework(u'Custom.framework'))

While functions in the custom framework were accessible, functions that required parameters to be passed by reference would not be handled correctly and the expected return tuple would be expressed as the original function return.

import objc as _objc
__bundle__ = _objc.initFrameworkWrapper("Custom",
                                        frameworkIdentifier="com.c1pher.Custom",
                                        frameworkPath=_objc.pathForFramework("/Library/Frameworks/Custom.framework"),
                                        globals=globals())

In the second example, the bridge functions as expected and the updated passed by reference parameters were accessible.

C1pher
  • 1,933
  • 6
  • 33
  • 52