找出ObjectAtIndex是否返回一个对象

时间:2013-07-18 05:55:29

标签: ios objective-c

有没有办法在([MyArray ObjectAtIndex:myindexpath.row])周围写一些catch语句,以便我可以在不抛出异常的情况下运行它?

换句话说,我想写这种表达方式:

if ([MyArray ObjectAtIndex:myindexpath.row]) {

// do some stuff if the object is in the array

else {

// do some other stuff

}

1 个答案:

答案 0 :(得分:2)

当然:使用逻辑&数学。

if (index < myArray.count) {
    // ...
}
相关问题