美文网首页iOS Developer
判断两个NSIndexPath是否相等

判断两个NSIndexPath是否相等

作者: Yancy_90 | 来源:发表于2016-04-28 12:01 被阅读1084次

    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;
    

    相关文章

      网友评论

        本文标题:判断两个NSIndexPath是否相等

        本文链接:https://www.haomeiwen.com/subject/cesxrttx.html