Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有 5 个 NSString,并且我想查看是否有任何字符串相同,有没有比使用[string isEqualToString:string2]一堆时间测试每个字符串更快的方法?
[string isEqualToString:string2]
如果您只有 5 个字符串,可能没有什么比一一比较更快的了。
但是如果你有很多字符串,创建一个包含所有字符串的 NSSet,然后只需检查字符串是否是该集合的成员,使用-[containsObject:].
-[containsObject:]