andreschneider
andreschneider

Reputation: 6574

How to check if the passed void function in a block is empty?

Are there any helpful hints how to check if the passed void function in a block is empty?

The output of the completion block is __NSGlobalBlock__, so the block isn't empty and check nil or NULL doesn't make sense ,logically.

Have a look at the code:

function calling example:

[aClass setCheckedItemVisible:YES animated:YES completion:^{
         //Empty block     
    }];

function:

-(void)setCheckedItemVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)())completion {
    ...

    (completion) ? ((void (^)())completion)() : NSLog(@"do other Stuff");

    ...
}

Thank you in advance.

Upvotes: 3

Views: 1639

Answers (1)

Mihai Fratu
Mihai Fratu

Reputation: 7663

Why don't you pass nil instead of an empty block? That way you should be able to check against nil.

Upvotes: 1

Related Questions