2

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

In this piece of code, the assertion 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?

Kristina
  • 15,859
  • 29
  • 111
  • 181

3 Answers3

3

NS_BLOCK_ASSERTIONS blocks assertions from functioning. Try deleting the definition.

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
1

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.

keyser
  • 18,829
  • 16
  • 59
  • 101
Naveen
  • 121
  • 1
  • 8
0

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.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200