문제

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?

도움이 되었습니까?

해결책

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]]) {
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top