objective-c - 您如何使用 ARC 处理 'require( ..., bail)' 语句?

标签 objective-c ios automatic-ref-counting llvm

我正在查看 Square Cam in Apple's sample code 的一些示例代码.我想在使用 ARC 的现代项目中复制它的一些功能。但是,有大量的 require 语句,例如:

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

生成编译器错误:

Goto into protected scope.

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

最佳答案

我遇到了同样的问题(使用相同的示例代码)。代码如下所示:

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

//Initialise some variables

bail:
//Deal with errors

我在带有声明的 block 周围添加了大括号,以明确它们的范围:

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

它解决了我的问题。通过查看这个,我还了解到您有时可以扩展构建错误以获得更多详细信息。

关于objective-c - 您如何使用 ARC 处理 'require( ..., bail)' 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11388853/

相关文章:

ios - 在 iOS 中写入随机值 AudioBuffer 时无法听到 'noise'

ios - 如何将颜色渐变应用于 UILabel 的背景?

iphone - 将 dispatch_async 与核心数据一起使用时获取 EXC_BAD_ACCESS

iphone - 更改导航项的背景并添加图像

iOS - 将两个视频合并为一个带音频的视频文件

ios - Quartz Performance 绘图大缓冲区

iOS B2B程序: can you "buy" the app with the same business you developed from?

ios - ARC 和 UIAlertView : unrecognized selector sent to instance

ios - topLevelObjects 的 loadNibNamed 泄漏

Objective-C/ALAssetslibrary - 如何检索 Assets 的正确路径