Created
July 8, 2012 06:53
-
-
Save tomohisa/3069721 to your computer and use it in GitHub Desktop.
Using ObjectAtIndex safely with this method.
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+IndexHelper.h | |
// C_POS | |
// | |
// Created by Tomohisa Takaoka on 6/14/12. | |
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSArray (IndexHelper) | |
-(id) safeObjectAtIndex:(NSUInteger)index; | |
@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+IndexHelper.m | |
// C_POS | |
// | |
// Created by Tomohisa Takaoka on 6/14/12. | |
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import "NSArray+IndexHelper.h" | |
@implementation NSArray (IndexHelper) | |
-(id) safeObjectAtIndex:(NSUInteger)index { | |
if (index>=self.count) { | |
return nil; | |
} | |
return [self objectAtIndex:index]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment