Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you handle 'require( ..., bail)' statements with ARC?

I'm looking through some of the sample code for the Square Cam in Apple's sample code. I want to replicate some of it's functionality in a modern project using ARC. However, there are a ton of require statements such as:

BOOL success = (destination != NULL);
require(success, bail);

Which generates the compiler error:

Goto into protected scope.

My question is -- what is the appropriate way to handle such statements in a project using ARC?

like image 337
Jim Jeffers Avatar asked Jul 09 '12 03:07

Jim Jeffers


2 Answers

I had the same problem (with the same sample code). The code looked like this:

BOOL success = (destination != NULL);
require(success, bail);

//Initialise some variables

bail:
//Deal with errors

I added braces around the block with the declarations to make their scope clear:

BOOL success = (destination != NULL);
require(success, bail);
{
    // *** Initialise some variables ***
}
bail:
{
    //Deal with errors
}

And it solved the problem for me. Through looking at this I also learned you can sometimes expand build errors to get more detail.

like image 87
lewis Avatar answered Nov 11 '22 04:11

lewis


Apparently bail is in a scope with one or more __block variables; this is not allowed. See http://clang.llvm.org/compatibility.html#blocks-in-protected-scope for more. The solution proposed there is to limit the scope of the __block variable(s), by putting them in brace-delimited blocks. This may not work always; YMMV.

like image 42
echristopherson Avatar answered Nov 11 '22 03:11

echristopherson