如何知道在发布版本中是否禁用了NSAssert? [英] How to know if NSAssert is disabled in release builds?

查看:451
本文介绍了如何知道在发布版本中是否禁用了NSAssert?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在iOS代码中看到断言,我谷歌它,并且知道它断言是真还是假。

I often saw "assert " in iOS code, I google it, and got to know it assert true or false.

我想知道这是否会自动在发布模式下禁用?

I want to know if this will auto disable in release mode?

推荐答案

使用NSAssert()及其随附数据。

Use NSAssert() and its companions.

在项目中为您的发布配置定义 NS_BLOCK_ASSERTIONS

in the project define NS_BLOCK_ASSERTIONS for your release configuration.

Xcode 4 tremplates disable 发行版配置中的NSAsserts 。它添加

Xcode 4 tremplates disable NSAsserts in the release configuration. It adds

-DNS_BLOCK_ASSERTIONS=1

到其他C标志的释放。

来自文档:

如果定义了预处理器宏 NS_BLOCK_ASSERTIONS ,则禁用断言。

Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined.

NSAssert宏评估条件和作为断言处理程序的前端。

The NSAssert macro evaluates the condition and serves as a front end to the assertion handler.

每个线程都有自己的断言处理程序,它是类 NSAssertionHandler 。调用时,断言处理程序会输出包含方法和类名(或函数名)的错误消息。然后它引发 NSInternalInconsistencyException 异常。如果condition的计算结果为NO,则宏在当前线程的断言处理程序上调用 handleFailureInMethod:object:file:lineNumber:description:,并将desc作为描述字符串传递。

Each thread has its own assertion handler, which is an object of class NSAssertionHandler. When invoked, an assertion handler prints an error message that includes the method and class names (or the function name). It then raises an NSInternalInconsistencyException exception. If condition evaluates to NO, the macro invokes handleFailureInMethod:object:file:lineNumber:description: on the assertion handler for the current thread, passing desc as the description string.

此宏只能在Objective-C方法中使用。

This macro should be used only within Objective-C methods.

这篇关于如何知道在发布版本中是否禁用了NSAssert?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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