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