I used this answer to sort 2 objects by date, and it worked perfectly: Get one NSArray
I now need to sort 3 objects by date, and can't quite modify what I have to get that right.
All of the Articles from the API/RSS feeds will be sorted by date in 1 tableView
.
Here's what I tried:
- (void)sortCombinedModel {
// All 3
[self.combinedModel sortUsingComparator:^NSComparisonResult(id a, id b, id c) {
NSDate *dateA, *dateB, *dateC;
dateA = ([a isKindOfClass:[FeedRSS self]])? ((FeedRSS *)a).pubDate : ((Data *)a).created_time : ((YaRSS *)a).pubDate;
dateB = ([b isKindOfClass:[FeedRSS self]])? ((FeedRSS *)b).pubDate : ((Data *)b).created_time : ((YaRSS *)b).pubDate;
dateC = ([c isKindOfClass:[FeedRSS self]])? ((FeedRSS *)c).pubDate : ((Data *)c).created_time : ((YaRSS *)c).pubDate;
return [dateB compare:dateA compare:dateC];
}];
}
Can you help me sort the 3 dates?
Additional info if needed:
I figured out how to modify this part - Have 3 API/RSS feeds coming in to one NSMutableArray
:
- (void)loadMedia {
self.combinedModel = [NSMutableArray array];
// Here's the #1
[self loadOneWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
// Here's the trick. call API2 here. Doing so will serialize these two requests
[self loadTwoWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
// Here's the trick. call API3 here. Doing so will serialize these two requests
[self loadThreeWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
[self sortCombinedModel];
[self.tableView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
}
Here's what sorting 2 dates looked like previously:
- (void)sortCombinedModel {
[self.combinedModel sortUsingComparator:^NSComparisonResult(id a, id b) {
NSDate *dateA, *dateB;
dateA = ([a isKindOfClass:[Feed self]])? ((Feed *)a).published : ((Data *)a).created_time;
dateB = ([b isKindOfClass:[Feed self]])? ((Feed *)b).published : ((Data *)b).created_time;
return [dateA compare:dateB];
}];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…