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 NSArray
s).
Another reason might be that the NS_BLOCK_ASSERTIONS
preprocessor macro is defined which disables NSAssert
.
精彩评论