Frage

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?

War es hilfreich?

Lösung

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]]) {
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top