Forum Archive

Invoking an NsBlock

JonB

Has anyone had success invoking an NSBlock? I have a python objc class that i have crated, which is accepting an ObjCBlock as an argument. The Block takes two arguments, and integer and a pointer (to the objc equivalent of a list). (This is the completion arg of for a PA2ConsoleCompletionProvider )

However, when calling ObjCInstance on the pointer, it returns an NSBlock. This has a method invoke(), but it does not want to take arguments. I feel like I have ben able to do this before, but I have forgotton how!

JonB

To be clear -- the block i want to call is one provided to me, not one i created.

dgelessus

I don't know how well the invoke method works... I think the proper way to invoke a block is to read it as a structure pointer (see http://clang.llvm.org/docs/Block-ABI-Apple.html for the struct format), take the invoke function pointer from there, cast it to the correct signature, and then call that.