如何判断对象是否在NSArray中? [英] How to tell if object is in NSArray?
本文介绍了如何判断对象是否在NSArray中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法判断某个物体是否在NSArray中?我将对象添加到数组的方式使得可以多次添加同一个对象,我想看看是否有方法可以查看该数组中是否已存在(任何地方)。
Is there a way to tell if a certain object is in an NSArray? The way I am adding objects to my array makes it possible for the same object to be added multiple times and I wanted to see if there was a way to see if it was already there (anywhere) in that array.
推荐答案
NSArray containsObject:
方法正是出于此目的,其完整签名为:
The NSArray containsObject:
method is precisely for this purpose, its full signature being:
- (BOOL)containsObject:(id)anObject
查看完整的 NSArray类参考文档以获取更多信息。
See the full NSArray Class Reference docs for more information.
这篇关于如何判断对象是否在NSArray中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文