If “a == b” is false when comparing two NSString objects

前端 未结 5 1645
梦毁少年i
梦毁少年i 2020-11-27 23:21

I have a class with an accessible method that passes back an NSString when called.

[MyClass getMyString]

The string variable

5条回答
  •  难免孤独
    2020-11-27 23:56

    You are comparing pointers to strings, rather than the strings themselves. You need to change your code to

    if (if([mySecondString isEqualToString:myString]) {
        ....
    }
    

提交回复
热议问题