Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #1587: Add second sorting descriptor "name" for sync device's frc. #1588

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Client/Frontend/Sync/SyncSettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ class SyncSettingsTableViewController: UITableViewController {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
configureCell(cell, atIndexPath: indexPath)

return cell
}

private func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
guard let frc = frc else {
log.error("FetchedResultsController is nil.")
return UITableViewCell()
return
}

switch indexPath.section {
Expand All @@ -210,8 +215,6 @@ class SyncSettingsTableViewController: UITableViewController {
default:
log.error("Section index out of bounds.")
}

return cell
}

private func setFullWidthSeparator(for cell: UITableViewCell) {
Expand Down Expand Up @@ -265,6 +268,14 @@ extension SyncSettingsTableViewController: NSFetchedResultsControllerDelegate {
case .delete:
guard let indexPath = indexPath else { return }
tableView.deleteRows(at: [indexPath], with: .fade)
case .update:
if let indexPath = indexPath, let cell = tableView.cellForRow(at: indexPath) {
configureCell(cell, atIndexPath: indexPath)
}

if let newIndexPath = newIndexPath, let cell = tableView.cellForRow(at: newIndexPath) {
configureCell(cell, atIndexPath: newIndexPath)
}
default:
log.info("Operation type: \(type) is not handled.")
}
Expand Down
3 changes: 2 additions & 1 deletion Data/models/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public final class Device: NSManagedObject, Syncable, CRUD {
fetchRequest.entity = Device.entity(context: context)

let currentDeviceSort = NSSortDescriptor(key: "isCurrentDevice", ascending: false)
fetchRequest.sortDescriptors = [currentDeviceSort]
let nameSort = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [currentDeviceSort, nameSort]

return NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context,
sectionNameKeyPath: nil, cacheName: nil)
Expand Down