NSIndexPath.h中有这么一个方法:
// comparison support
- (NSComparisonResult)compare:(NSIndexPath *)otherObject; // sorting an array of indexPaths using this comparison results in an array representing nodes in depth-first traversal order
它的返回值NSComparisonResult
是一个枚举
typedef NS_ENUM(NSInteger, NSComparisonResult) {
NSOrderedAscending = -1L,
NSOrderedSame,
NSOrderedDescending
};
因此判断两个NSIndexPath是否相可以这样写
BOOL isEqual = ([indexPath1 compare:indexPath2] == NSOrderedSame) ? YES : NO;
网友评论