I have a function in my objective c file (lets say class MyBlockExecutor):
+ (void) runBlockFromDictionary: (NSDictionary*) blocksDict andKey: (NSString*) key
{
if ( [blocksDict objectForKey: key] != nil )
{
((MyBlock)[blocksDict objectForKey: key])();
}
}
Now, I want to call this function from Swift. Here is my swift call:
MyBlockExecutor.runBlock(from: [
"key1":{ ()->Void in
print("block for key1 called")
}
], andKey: "key1")
This crashes my app. I am getting EXC_BAD_ACCESS error on this line:
((MyBlock)[blocksDict objectForKey: key])();
Although, calling the same function from Objective-C works perfectly fine. Also, I've defined MyBlock as :
typedef void (^MyBlock)(); //defined in MyBlockExecutor.h file
How do I resolve this?
Edit: I am open to changes in the objective c function, I just somehow need to pass a collection of closures from swift to my objective c function and run the block.