4

I have an array of dictionaries, that stores blocks and queues. After some method I need to execute it.

for (NSDictionary * dict in self.arrayOfBlocksAndQueues) {
    if (!dict[@"block"] || !dict[@"queue"]) {
        continue;
    }
    dispatch_block_t block = dict[@"block"];
    dispatch_async(dict[@"queue"], ^{
        block();
    });
}

So my question is, how can I check in runtime, that dict[@"block"] and dict[@"queue"] are exactly the type I’m expected? I have a typedef void(^handler)(); and I need to be sure that dict[@"block”] is type of handler. As I know, blocks and queues are in fact objective-c objects, but don’t conforms to <NSObject> protocol. So, is there anyway to do it?

Thanks in advance!

Alfred Zien
  • 1,025
  • 1
  • 11
  • 31

1 Answers1

0

You can create a class with a block/queue property for easy manipulation. Try setting your block and queue properies with this class and add this objects in dictionary.

//Block class
@interface myBlock : NSObject

@property (assign) dispatch_block_t block;

@end

//Queue class
@interface myQueue : NSObject

@property (assign) dispatch_queue_t block;

@end
Mohd Iftekhar Qurashi
  • 2,385
  • 3
  • 32
  • 44