Skip to content

Instantly share code, notes, and snippets.

@BetrayalPromise
Forked from aegzorz/NSArray+FirstObject.h
Created April 19, 2016 08:15
Show Gist options
  • Select an option

  • Save BetrayalPromise/7202f1d158ce3ad43777a930cee47584 to your computer and use it in GitHub Desktop.

Select an option

Save BetrayalPromise/7202f1d158ce3ad43777a930cee47584 to your computer and use it in GitHub Desktop.
Gets the first object in an array or returns nil for empty array.
//
// NSArray+FirstObject.h
//
#import <Foundation/Foundation.h>
@interface NSArray (FirstObject)
- (id)firstObject;
@end
//
// NSArray+FirstObject.m
//
#import "NSArray+FirstObject.h"
@implementation NSArray (FirstObject)
- (id)firstObject
{
return self.count > 0 ? self[ 0 ] : nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment