comparison of two strings fails

后端 未结 4 516
借酒劲吻你
借酒劲吻你 2020-12-21 14:16

I make a comparison of two strings which are obviously identical. Unfortunately my if clause doesn´t work as expected:

NSLog(@\"%@ == %@ ?\",strippedString1,         


        
4条回答
  •  醉话见心
    2020-12-21 14:46

    Important part: you meant to use isEqualToString

    Using == will check for equality of of the pointer, i.e. it will tell you if the two objects you are comparing are actually the same instance.

    Instead I think you meant to check that the contents are the same, but accourding to the appledocs you will want to use isEqualToString when you know the two objects are strings as it is much faster than isEqual.

提交回复
热议问题