Last active
November 27, 2021 06:58
-
-
Save aegzorz/5797393 to your computer and use it in GitHub Desktop.
Gets the first object in an array or returns nil for empty array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSArray+FirstObject.h | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSArray (FirstObject) | |
- (id)firstObject; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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
In iOS 7 NSArray have public property firstObject.