Solution:
Turns out the problem doesn't exist in this code. It's because the foo is being called in a UIViewController when it's being destroyed. Thus, when the asynchronous foo calls the completion block, it breaks due to a call to something that no longer exists.
Apologies to those whose time I took up with this. :/ Hopefully this will be a lesson to others to make sure their completion handler still exists at the time of completion.
Before I begin, I've looked at Wait for many asynchronous calls to perform callback and Chaining Completion Blocks, but the solutions in both do not fix my problem.
Situation:
I've got a method, foo, that has a completion block, but it calls another method, bar, with a completion block. foo calls its completion block during bar's execution of the completion block. An example is below.
-(void) foo:(void(^)())completion{
...
bar:^{
...
completion();
}
}
-(void) bar:(void(^)())completion{
...
completion();
}
When I do this, I get a bad access in foo's call to completion.
Do I need to make a __block
copy of foo's completion parameter?
If so, how do I make it since __block (void(^)()) completionCopy;
doesn't even pass the compiler?