NSArray difference between first

2017-12-14  本文已影响0人  iLynn

NSArray *array = [NSArray new];
id obj1 = [array firstObject]; // this is giving nil value
id obj2 = [array objectAtIndex:0]; // this line crashes

Using firstObject is a system defined API which returns nil if there is none. But if you try to access objectAtIndex it will give NSRange exception and app will crash.

上一篇 下一篇

猜你喜欢

热点阅读