From 28c4ea82e547921256168f035a90278dbbea43c7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 28 Jan 2018 11:33:04 -0800 Subject: [PATCH] Consider sort direction when sorting the Article array for the timeline. --- .../MainWindow/Timeline/ArticleArray.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Evergreen/MainWindow/Timeline/ArticleArray.swift b/Evergreen/MainWindow/Timeline/ArticleArray.swift index 26df12010..531ea2247 100644 --- a/Evergreen/MainWindow/Timeline/ArticleArray.swift +++ b/Evergreen/MainWindow/Timeline/ArticleArray.swift @@ -64,9 +64,16 @@ extension Array where Element == Article { return indexes } - func sortedByDate() -> ArticleArray { + func sortedByDate(_ sortDirection: ComparisonResult) -> ArticleArray { - return sorted(by: articleComparator) + let articles = sorted { (article1, article2) -> Bool in + if sortDirection == .orderedDescending { + return article1.logicalDatePublished > article2.logicalDatePublished + } + return article1.logicalDatePublished < article2.logicalDatePublished + } + + return articles } func canMarkAllAsRead() -> Bool { @@ -95,12 +102,4 @@ private extension Array where Element == Article { return rowForArticleID(article.articleID) } - - // MARK: Sorting - - func articleComparator(_ article1: Article, article2: Article) -> Bool { - - return article1.logicalDatePublished > article2.logicalDatePublished - } - }