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; }];