Skip to content

Commit

Permalink
add ascend or descend support
Browse files Browse the repository at this point in the history
  • Loading branch information
David Fu committed Jul 31, 2015
1 parent 3dfa303 commit a1f1abf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Pod/Classes/SMBFetchedResults.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@

@property (readonly, nonatomic, assign) NSStringCompareOptions options;

@property (readonly, nonatomic, assign) BOOL ascend;

@property (readonly, nonatomic, assign) BOOL moving;

@property (readonly, nonatomic, assign) BOOL sorted;

- (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 <SMBFetchedResultsProtocol>)object;
- (void)appendObjectsFromArray:(NSArray *)otherArray;
Expand Down
11 changes: 7 additions & 4 deletions Pod/Classes/SMBFetchedResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,7 +128,7 @@ - (void)sortedResultWithOrderedSet:(NSMutableOrderedSet *)orderedSet {
}

if (result != NSOrderedSame)
return result;
return self.ascend? result: -result;
}
return NSOrderedSame;
}];
Expand Down

0 comments on commit a1f1abf

Please sign in to comment.