But it does have a lastObject, anybody know why?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My guess is because
lastObjectreduces more boilerplate code. You use[array lastObject]to replace either[array objectAtIndex:array.count - 1]orarray[array.count - 1]using modern Objective-C syntax.Whereas in the case of
firstObjectyou can simply check[array objectAtIndex:0]orarray[0].It just helps streamline things to be able to call
lastObjectinstead of typing out that function.Update
As @Nathaniel Symer suggested in his comment above,
firstObjecthas previously been available but only in private API (I believe since iOS 4). However, as of the release of the iOS 7 SDK,firstObjectis now publicly available!