Reputation: 758
NSMutableDictionary* actions = [[NSMutableDictionary alloc] init];
actions[@"run"] = ^ () {
NSLog(@"Hello");
};
actions[@"run"]();
Xcode reports the error Called object type 'id' is not a function or function pointer
when I invoke the block in NSDictionary.
How I can invoke block stored in NSDictionary?
Upvotes: 2
Views: 764
Reputation: 26383
Is just a problem of cast,try the verbose version :
(void) (^dictBlock)(void)) = actions[@"run"];
dictClock()
Upvotes: 0
Reputation: 5076
You should create a local variable to cast id to block type.
void(^block)(void) = [actions objectForKey:@"run"];
if(block)
{
block();
}
Upvotes: 2