ios - firstObject vs objectAtIndex:0

来源:互联网 发布:小米网络音响aux 编辑:程序博客网 时间:2024/05/07 23:52

There is one key difference. Using firstObject returns nil if there is none. Using objectAtIndex:0 will crash your app(throws an exception) if there is no object there.From a user experience perspective, crashing is highly advocated against, so it is safer to use firstObject.

BUT the biggest pitfall: firstObject has been available since iOS 4, but was a private API until iOS 7.


http://stackoverflow.com/questions/21923281/ios-firstobject-vs-objectatindex0

0 0
原创粉丝点击