NSString: isEqual vs. isEqualToString

后端 未结 5 750
攒了一身酷
攒了一身酷 2020-11-28 06:36

What is the difference between isEqual: and isEqualToString:?

Why are classes adding isEqualTo* methods (isEqualToArray for NSArray, isEqua

5条回答
  •  星月不相逢
    2020-11-28 06:54

    isEqual: compares a string to an object, and will return NO if the object is not a string. isEqualToString: is faster if you know both objects are strings, as the documentation states:

    Special Considerations

    When you know both objects are strings, this method is a faster way to check equality than isEqual:.

    isEqualTo is used to provide specific checks for equality. For instance; isEqualToArray: checks that the arrays contain an equal number of objects, and that the objects at a given index return YES for the isEqual: test.

提交回复
热议问题