Question

I have a probelm with a String Variable that appears as null.

NSLog(@"rate : %@",_rate);     //-->       rate : <null>  

The app crashes when I try:

if ([_rate length]== 0)    //app crash

with message: -[NSNull length]: unrecognized selector sent to instance

The strange thing is that using:

 if (_rate == nil) and     if (_rate == NULL)

variable it seems not nill or null.

Any suggestions?

Was it helpful?

Solution

This means that _rate is an instance of NSNull.

if (rate == [NSNull null]) {
    // It's set to "NSNull null"
} else {
    // It's a value you can work with
}

To avoid the warning (since rate is an NSString) you can do:

if ([rate isEqual:[NSNull null]]) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top