如何使用ARC处理'require(...,bail)'语句? [英] How do you handle 'require( ..., bail)' statements with ARC?

查看:87
本文介绍了如何使用ARC处理'require(...,bail)'语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 Apple的示例代码中的Square Cam .我想在使用ARC的现代项目中复制其某些功能.但是,有大量的require语句,例如:

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.

我的问题是-在使用ARC的项目中处理此类语句的适当方法是什么?

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

推荐答案

我遇到了相同的问题(具有相同的示例代码).代码如下:

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.

这篇关于如何使用ARC处理'require(...,bail)'语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆