Add firstObject to NSArray and pals

Originator:tony
Number:rdar://13650524 Date Originated:15-Apr-2013 03:29 PM
Status:Closed Resolved:October 4 2013, 9:07 PM
Product:OS X SDK Product Version:10.8
Classification:Enhancement Reproducible:Not Applicable
 
Summary:
Presently, there is no way to safely and quickly retrieve the first object in an array/collection. `objectAtIndex:` throws an exception if you request an out of bounds object, whereas `lastObject` safely does what it says on the box.

Given how common it is to request the first object in an array, I'd love to see a simple addition to these guys:

-(id)firstObject
{
    if ([self count] > 0) {
        return [self objectAtIndex:0];
    }

    return nil;
}

Any chance of that happening? I'll file the same against the iOS SDK.

Comments

Here's the iOS version

http://www.openradar.me/13650523


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!