Archived
1

Added Some Helpers

This commit is contained in:
Kim Wittenburg
2014-09-07 16:46:50 +02:00
parent 205de83a28
commit 02d7398ee2
2 changed files with 39 additions and 0 deletions

View File

@@ -58,4 +58,29 @@
return [[self indexPathByRemovingLastIndex] indexPathByAddingIndex:lastIndex];
}
- (NSIndexPath *)indexPathWithLength:(NSUInteger)length
{
NSIndexPath *indexPath = [[NSIndexPath alloc] init];
for (NSUInteger position = 0; position < length; position++) {
indexPath = [indexPath indexPathByAddingIndex:[self indexAtPosition:position]];
}
return indexPath;
}
- (NSIndexPath *)commonIndexPathWith:(NSIndexPath *)indexPath
{
NSIndexPath *commonPath = [[NSIndexPath alloc] init];
NSUInteger length = MIN(self.length, indexPath.length);
for (NSUInteger position = 0; position < length; position++) {
NSUInteger selfIndex = [self indexAtPosition:position];
NSUInteger otherIndex = [indexPath indexAtPosition:position];
if (selfIndex == otherIndex) {
commonPath = [commonPath indexPathByAddingIndex:selfIndex];
} else {
break;
}
}
return commonPath;
}
@end