What is the difference in the usage of the methods firstObject vs objectAtIndex:0?

好久不见. 提交于 2019-12-01 15:15:43

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!