I have a objc method like this;
@ implementation of Class1
- (void)execute:(void (^)(Class2* target, NSUInteger idx))block
{
...
}
I want to use this execute method in python, i have build a python objective-c bridge data and it seems to be generated correctly as:
<class name='Class1'>
<method selector='execute:'>
<arg function_pointer='true' type='@?' index='0'>
<arg type='@'/>
<arg type='I' type64='Q'/>
<retval type='v'/>
</arg>
</method>
But when i define a function like this:
def myFunc (dev, index):
// do something with dev
print("Hello")
and try to use this as block
class1_obj.execute_(myFunc)
Python throw an errors as:
objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector myFunc at 0x105b3a3f0>
I also tried with lambda function, no use.
I also tried to create a callable class as:
>>> class myCallable(object):
... def __init__(self,name):
... print "Init"
... def __repr__(self):
... return "string init"
... def __call__(self, dev, index):
... # do something with dev
... print("hello")
but python throw an error like this:
TypeError: Sorry, cannot create IMP for instances of type myCallable
I am wondering where did I do wrong here?
<arg function_pointer='true' type='@?' index='0'>should instead be<arg block='true' index='0'>. I'm not at all sure that will solve your problem, though. How did you generate that metadata?execute_, or inside, when you call the "Block"?