     
     // MARK: - Sorting
     
-    fileprivate var sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: "savedDate", ascending: false) {
+    fileprivate var sort: (descriptor: NSSortDescriptor, action: UIAlertAction?) = (descriptor: NSSortDescriptor(key: "savedDate", ascending: false), action: nil) {
         didSet {
-            guard sortDescriptor != oldValue else {
+            guard sort.descriptor != oldValue.descriptor else {
                 return
             }
             setupCollectionViewUpdaterAndFetch()

            let searchPredicate = NSPredicate(format: "(displayTitle CONTAINS[cd] '\(searchString)') OR (snippet CONTAINS[cd] '\(searchString)')")
            articleRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [basePredicate, searchPredicate])
        }
        articleRequest.sortDescriptors = [sortDescriptor]
        fetchedResultsController = NSFetchedResultsController(fetchRequest: articleRequest, managedObjectContext: dataStore.viewContext, sectionNameKeyPath: nil, cacheName: nil)
    }
    

        do {
            try fetchedResultsController.performFetch()
        } catch let err {
            assertionFailure("Couldn't sort by \(sort.descriptor.key ?? "unknown key"): \(err)")
        }
        collectionView.reloadData()
    }
    
    fileprivate lazy var sortActions: (title: UIAlertAction, recentlyAdded: UIAlertAction) = {
        let titleAction = UIAlertAction(title: "Title", style: .default) { (action) in
            self.sort = (descriptor: NSSortDescriptor(key: "displayTitle", ascending: true), action: action)
        }
        let recentlyAddedAction = UIAlertAction(title: "Recently added", style: .default) { (action) in
            self.sort = (descriptor: NSSortDescriptor(key: "savedDate", ascending: false), action: action)
        }
        return (title: titleAction, recentlyAdded: recentlyAddedAction)
    }()
    
    fileprivate lazy var sortAlert: UIAlertController = {
        let alert = UIAlertController(title: "Sort saved articles", message: nil, preferredStyle: .actionSheet)
        alert.addAction(sortActions.title)
        alert.addAction(sortActions.recentlyAdded)
        let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (actions) in
            self.dismiss(animated: true, completion: nil)
        }
