Objective-C中的NS_BLOCK_ASSERTIONS [英] NS_BLOCK_ASSERTIONS in Objective-C

查看:510
本文介绍了Objective-C中的NS_BLOCK_ASSERTIONS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone应用程序中使用NSAssert()调用,而我从Apple文档中的理解是,如果定义了NS_BLOCK_ASSERTIONS,则断言不会被编译到代码中。

I am using NSAssert() calls within an iPhone application and my understanding from the Apple docs is that assertions are not compiled into the code if NS_BLOCK_ASSERTIONS is defined.

要关闭断言,在头文件中我声明:#define NS_BLOCK_ASSERTIONS

To turn off assertions, in a header file I declare: #define NS_BLOCK_ASSERTIONS

但是,断言代码似乎仍然运行。

However, the assert code still seems to run.

有没有我在这里遗失的东西?

Is there something I am missing here?

谢谢

John

推荐答案

如果您根据其中一个标准模板创建了Xcode项目,那么Cocoa头文件(包括 NSException.h 其中包含 NSAssert 宏)将在项目中的任何其他文件之前进行预处理。因此,任何项目的头文件或实现文件中的 #define NS_BLOCK_ASSERTIONS 不会对 NSAssert 宏产生影响。

If you created your Xcode project based on one of the standard templates, the Cocoa headers (including NSException.h which contains the NSAssert macros) will get preprocessed before any other files in the project. A #define NS_BLOCK_ASSERTIONS in any of the project's header or implementation files therefore has no effect on the NSAssert macros.

尝试将 NS_BLOCK_ASSERTIONS 放入目标甚至项目的预处理器宏中(仅适用于发行版配置):

Try putting NS_BLOCK_ASSERTIONS into the preprocessor macros of your target or even project (for the release configuration only):

或者将 #define NS_BLOCK_ASSERTIONS 放入 #import< Cocoa / Cocoa之前的前缀(.pch)标题中。 h> #import< Foundation / Foundation.h> 行。

这篇关于Objective-C中的NS_BLOCK_ASSERTIONS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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