本文介绍了NSArray超出范围检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
noobie问题。什么是最好的方法来检查NSArray或NSMutableArray的索引是否存在。
这是我试过的:
if(sections = [arr objectAtIndex:4]) { /*.....*/ }或
sections = [arr objectAtIndex:4] if(sections == nil) { /*.....*/ }但两者都会抛出一个超出范围错误,不允许我继续
)
提前感谢
解决方案pre> if(array.count> 4){ sections = [array objectAtIndex:4]; }
noobie question.. What is the best way to check if the index of an NSArray or NSMutableArray exists. I search everywhere to no avail!!
This is what I have tried:
if (sections = [arr objectAtIndex:4]) { /*.....*/ }or
sections = [arr objectAtIndex:4] if (sections == nil) { /*.....*/ }but both throws an "out of bounds" error not allowing me to continue
(do not reply with a try catch because thats not a solution for me)
Thanks in advance
解决方案 if (array.count > 4) { sections = [array objectAtIndex:4]; }
更多推荐
NSArray超出范围检查
发布评论