Reputation: 32093
I'm trying to make a failsafe to guarantee a null block is never attempted to be executed. To do this, I use a custom property getter, which returns the block if it's not null, else it returns an empty block. However! The if
statement is always entered! Then, I get an EXC_BAD_ACCESS
when it tries to return the block!
It looks like the block isn't defined, as it has a value of 0x0000000000000000
, and its __FuncPtr
is NULL
, so why is this if
statement being entered?
My block is declared as:
@property (nonatomic, assign) void (^pinPadCompletionBlock)(bool);
Upvotes: 0
Views: 120
Reputation: 32093
The problem lies in how the property is declared. Blocks cannot be declared as assign
. Simply change your declaration to use copy
, instead:
@property (nonatomic, copy) void (^pinPadCompletionBlock)(bool);
Additionally, if you look further than the __FuncPtr
, you'll see that there are set values inside the block, meaning that the block isn't actually null, despite the debugger readout. So, the code is behaving properly in entering that statement, and I think you'll find that after changing assign
to copy
, the block's value will be something more obviously non-null when you get to the if
statement..
Upvotes: 1