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

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

    var dataStore: MWKDataStore!
    
    fileprivate func setupFetchedResultsController(with dataStore: MWKDataStore) {
        // hax
        sortActions.title.setValue(false, forKey: "checked")
        sortActions.recentlyAdded.setValue(false, forKey: "checked")
        let checkedAction = sort.action ?? sortActions.recentlyAdded
        checkedAction.setValue(true, forKey: "checked")
        
        let articleRequest = WMFArticle.fetchRequest()
        let basePredicate = NSPredicate(format: "savedDate != NULL")
