Hello, I'm playing with creating classes with the objc_util module, and I am running into a problem. I want a class that contains objc methods that can access the underlying python object. For example,
class TestClass(object):
def __init__(self):
self.objcInstance = objc_util.create_objc_class(
"TestClass",
methods = [self.testMethod]
).alloc().init()
self.testVariable = 1
pass
def testMethod(self, _self, _cmd):
print(self.testVariable)
pass
TestClass().objcInstance.testMethod()
But when I run this i get the following error,
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/08CF4A94-F824-408A-B12B-53EA02F43C24/Pythonista3/Documents/Projects/musicruntime/queueviewer.py", line 48, in <module>
TestClass().objcInstance.testMethod()
File "/private/var/mobile/Containers/Shared/AppGroup/08CF4A94-F824-408A-B12B-53EA02F43C24/Pythonista3/Documents/Projects/musicruntime/queueviewer.py", line 39, in __init__
methods = [self.testMethod]
File "/var/containers/Bundle/Application/E768493A-4B9B-48EB-82D1-FADC51CC89B6/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 1191, in create_objc_class
_add_method(method, class_ptr, superclass, basename, protocols)
File "/var/containers/Bundle/Application/E768493A-4B9B-48EB-82D1-FADC51CC89B6/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 1153, in _add_method
raise ValueError('%s has %i arguments (expected %i)' % (method, len(argspec.args), len(argtypes)))
ValueError: <bound method TestClass.testMethod of <__main__.TestClass object at 0x1180f0f28>> has 3 arguments (expected 2)
The only I can think to solve this would be either creating a global variable or turning TestClass into a singleton, but that isn't ideal.
Thanks for any help!.