如何检查对象是否存在于 NSMutableArray 的某个索引处? [英] How do I check if an object exists at a certain index of an NSMutableArray?
本文介绍了如何检查对象是否存在于 NSMutableArray 的某个索引处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我如何验证索引 3 处是否有项目?
For instance, how could I verify if there is an item at the index 3?
NSArray
中的对象是从类Animal"实例化的.
The objects in the NSArray
are instantiated from the class "Animal."
推荐答案
好吧,既然 NSMutableArray
必须保存非 nil 对象,只要数组足够大,你就知道有 东西在索引i
:
Well, since NSMutableArray
has to hold non-nil objects, as long as the array is big enough, you know there's something at index i
:
if ([myArray count] > 3) {
id myObj = [myArray objectAtIndex:3];
...
}
如果您需要检查其他内容,例如确保它没有对 NSNull 单例的引用,您可以检查
If you needed to check something elsek, like say make sure it didn't have a reference to the NSNull singleton, you could then check
if (myObj != [NSNull null]) ...
这篇关于如何检查对象是否存在于 NSMutableArray 的某个索引处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文