我曾认为NSAssert
不能使用printf
格式说明符,但是这个:
NSAssert(0, @"%@%@", @"foo", @"bar");
这个功能的效果就像你所期望的那样:
*** Assertion failure in -[MyClass myMethod], <Path>/MyClass.m:84
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'foobar'
当NSAssert
能够正常使用时,为什么还需要使用NSAssert1
,NSAssert2
等函数呢?
这是针对Xcode 4.0和iOS 4.3 SDK的,如果有所不同,我会更新标签的。