String compare Objective-C

前端 未结 2 457
说谎
说谎 2021-01-17 01:08

I\'ve been struggling with a simple comparison but I can\'t get it to work. I´m reading a XML file and I need to compare data from it in order to show the right picture.

2条回答
  •  天涯浪人
    2021-01-17 01:53

    If the larmClass property is a string, make sure that it is actually one character in length (i.e. it doesn't have any leading or trailing whitespace that was accidentally included when parsing the XML). If the larmClass property truly is an NSString containing the letter ‘A’ then [aLarm.larmClass isEqualToString:@"A"] will return YES.

    Do a:

    NSLog(@"%u, %@", [aLarm.larmClass length], aLarm.larmClass);
    

    and just make sure that it shows “1, A”.

提交回复
热议问题