search

Home  >  Q&A  >  body text

IOS新手问个字符串判断为空的问题

NSLog(@"echo>>>>>>%@",echo);
 NSLog(@"echo>>>>>>%d",echo==nil);
 NSLog(@"echo>>>>>>%d",[echo length]);
    
016-06-14 15:13:29.739 OA_App[4990:1558049] echo>>>>>><null>

2016-06-14 15:13:29.740 OA_App[4990:1558049] echo>>>>>>0 //这里不应该是1 true吗?

2016-06-14 15:13:29.740 OA_App[4990:1558049] -[NSNull length]: unrecognized selector sent to instance 0x34c15850

高洛峰高洛峰2889 days ago204

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:15:47

    NSNull is not equal to nil

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:15:47

    It is not nil, it is an instance of NSNull. If you want to judge, it should be enough to judge whether it is NSNull class.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:15:47

    Directly determine the length of the string, if it is equal to 0, it is empty

    reply
    0
  • Cancelreply