开发者

NSAssert doesn't work

I'm trying to use NSAssert in my code but it doesn't do a thing.

In this piece of code, the as开发者_开发问答sertion should fail but doesn't:

    MSLog(@"cross.obj = %@",[cross obj]);
    NSAssert([cross obj]!=nil,@"[cross obj] == nil");

The output of this is:

cross.obj = (null)

What could be the problem?


NS_BLOCK_ASSERTIONS blocks assertions from functioning. Try deleting the definition.


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.


The reason might be that the result from [cross obj] is [NSNull null], not nil.

The output probably is <null> which does not mean NULL or nil but the NSNull singleton object. This object is used as a placeholder where nil is not an option (for instance in NSArrays).

Another reason might be that the NS_BLOCK_ASSERTIONS preprocessor macro is defined which disables NSAssert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜