Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

iphone - NS_BLOCK_ASSERTIONS in Objective-C

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.

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?

Thanks

John

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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

GCC_PREPROCESSOR_DEFINITIONS = NS_BLOCK_ASSERTIONS

Or put #define NS_BLOCK_ASSERTIONS into the prefix (.pch) header before the #import <Cocoa/Cocoa.h> or #import <Foundation/Foundation.h> lines.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...