IF clause is not validating NSString function return?

后端 未结 2 822
南笙
南笙 2020-12-12 04:50

I have the function below that validates the return of another function (function searchPlaces that returns NSString). When I run it, it seems that the if clause is not bein

相关标签:
2条回答
  • 2020-12-12 05:27

    You should not comparing NSStrings with the == operator. The == operator performs reference equality on Objective-C object types: it only returns true if both operands refer to the exact same object. Even if two strings are copies of each other, == will return false if they refer to different instances.

    You want to use value equality instead. You can compare strings using the -isEqualToString: method:

    if ([novaurl isEqualToString:@"OK"]) {
        ...
    }
    
    0 讨论(0)
  • 2020-12-12 05:50

    You should use isEqualToString: method of NSString to check for equality of strings. == operator does a pointer comparison and sometimes it will return NO although the contents of the strings are the same.

    0 讨论(0)
提交回复
热议问题