我正在尝试NSAssert在我的代码中使用,但它没有做任何事情。
在这段代码中,断言应该失败但不会:
MSLog(@"cross.obj = %@",[cross obj]);
NSAssert([cross obj]!=nil,@"[cross obj] == nil");
这个的输出是:
cross.obj = (null)
可能是什么问题呢?
我正在尝试NSAssert在我的代码中使用,但它没有做任何事情。
在这段代码中,断言应该失败但不会:
MSLog(@"cross.obj = %@",[cross obj]);
NSAssert([cross obj]!=nil,@"[cross obj] == nil");
这个的输出是:
cross.obj = (null)
可能是什么问题呢?
NS_BLOCK_ASSERTIONS阻止断言起作用。尝试删除定义。
The reason behind this is that there is a difference between a nil and a null value.
So please check it with other examples.
It will work.
原因可能是结果[cross obj]是[NSNull null],不是nil。
输出可能<null>不是指单例对象,NULL也可能nil是NSNull单例对象。此对象用作nil不是选项的占位符(例如在NSArrays 中)。
另一个原因可能NS_BLOCK_ASSERTIONS是定义了预处理器宏,它禁用了NSAssert.