From a1f1abf0c437945d8fb08a5fdb95f1d4fee2c2f0 Mon Sep 17 00:00:00 2001 From: David Fu Date: Fri, 31 Jul 2015 14:50:39 +0800 Subject: [PATCH] add ascend or descend support --- Pod/Classes/SMBFetchedResults.h | 7 ++++++- Pod/Classes/SMBFetchedResults.m | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/SMBFetchedResults.h b/Pod/Classes/SMBFetchedResults.h index 2e932d6..bb5fac4 100644 --- a/Pod/Classes/SMBFetchedResults.h +++ b/Pod/Classes/SMBFetchedResults.h @@ -25,6 +25,8 @@ @property (readonly, nonatomic, assign) NSStringCompareOptions options; +@property (readonly, nonatomic, assign) BOOL ascend; + @property (readonly, nonatomic, assign) BOOL moving; @property (readonly, nonatomic, assign) BOOL sorted; @@ -32,7 +34,10 @@ - (void)sortedResultWithOrderedSet:(NSMutableOrderedSet *)orderedSet; - (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData; -- (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData sortKeyPaths:(NSString *)sortKeyPaths sortOptions:(NSStringCompareOptions)options; +- (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData + sortKeyPaths:(NSString *)sortKeyPaths + ascend:(BOOL)ascend + sortOptions:(NSStringCompareOptions)options; - (void)appendObject:(id )object; - (void)appendObjectsFromArray:(NSArray *)otherArray; diff --git a/Pod/Classes/SMBFetchedResults.m b/Pod/Classes/SMBFetchedResults.m index f880d84..2f96c36 100644 --- a/Pod/Classes/SMBFetchedResults.m +++ b/Pod/Classes/SMBFetchedResults.m @@ -43,14 +43,17 @@ @implementation SMBFetchedResults #pragma mark - life cycle - (instancetype)init { - return [self initWithMutableData:[NSMutableOrderedSet orderedSet] sortKeyPaths:nil sortOptions:0]; + return [self initWithMutableData:[NSMutableOrderedSet orderedSet] sortKeyPaths:nil ascend:YES sortOptions:0]; } - (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData { - return [self initWithMutableData:mutableData sortKeyPaths:nil sortOptions:0]; + return [self initWithMutableData:mutableData sortKeyPaths:nil ascend:YES sortOptions:0]; } -- (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData sortKeyPaths:(NSString *)sortKeyPaths sortOptions:(NSStringCompareOptions)options { +- (instancetype)initWithMutableData:(NSMutableOrderedSet *)mutableData + sortKeyPaths:(NSString *)sortKeyPaths + ascend:(BOOL)ascend + sortOptions:(NSStringCompareOptions)options { self = [super init]; if (self) { _data = mutableData; @@ -125,7 +128,7 @@ - (void)sortedResultWithOrderedSet:(NSMutableOrderedSet *)orderedSet { } if (result != NSOrderedSame) - return result; + return self.ascend? result: -result; } return NSOrderedSame; }];