Skip to content

Instantly share code, notes, and snippets.

@CodaFi
Created February 17, 2013 07:39
Show Gist options
  • Save CodaFi/4970568 to your computer and use it in GitHub Desktop.
Save CodaFi/4970568 to your computer and use it in GitHub Desktop.
Create NSIndexPaths the easy way.
@interface NSIndexPath (CFIAdditions)
#ifdef TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED <= 60000
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;
#endif
@end
@implementation NSIndexPath (CFIAdditions)
#ifdef TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED <= 60000
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section {
NSUInteger indexArr[] = {section, row};
return [NSIndexPath indexPathWithIndexes:indexArr length:2];
}
+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section {
NSUInteger indexArr[] = {section, item};
return [NSIndexPath indexPathWithIndexes:indexArr length:2];
}
#endif
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment