本文介绍了NSString:isEqual vs. isEqualToString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

isEqual: isEqualToString:有什么区别?

为什么类添加isEqualTo *方法(isEqualToArray用于NSArray,isEqualToData用于NSData,...)而不是仅覆盖 isEqual:

Why are classes adding isEqualTo* methods (isEqualToArray for NSArray, isEqualToData for NSData, ...) instead of just overriding isEqual: ?

推荐答案

isEqual:将字符串与对象进行比较,并返回 NO 如果对象不是字符串。 isEqualToString:更快,如果你知道两个对象都是字符串,因为状态:

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:

当你知道这两个对象都是字符串时,方法检查等于 isEqual:

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

isEqualTo< Class> 用于提供对等式的特定检查。例如; 检查数组是否包含相等数量的对象,并且给定索引处的对象返回 isEqual:测试。

isEqualTo<Class> 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.

这篇关于NSString:isEqual vs. isEqualToString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 22:56