3lvis / DATASource

Core Data's NSFetchedResultsController wrapper for UITableView and UICollectionView
Other
106 stars 27 forks source link

NSSortDescriptor and sectionName #65

Closed 3lvis closed 7 years ago

3lvis commented 8 years ago

When using sortDescriptors with sectionName, the sectioName descriptor has to be in the top, this is a stupid bug by NSFetchedResultsController.

Wrong:

let request: NSFetchRequest = NSFetchRequest(entityName: "User")
request.sortDescriptors = [
    NSSortDescriptor(key: "count", ascending: true),
    NSSortDescriptor(key: "name", ascending: true),
    NSSortDescriptor(key: "firstLetterOfName", ascending: true)
]

let dataSource = DATASource(tableView: self.tableView, cellIdentifier: CustomCell.Identifier, fetchRequest: request, mainContext: self.dataStack!.mainContext, sectionName: "firstLetterOfName") { cell, item, indexPath in
}

Correct:

let request: NSFetchRequest = NSFetchRequest(entityName: "User")
request.sortDescriptors = [
    NSSortDescriptor(key: "firstLetterOfName", ascending: true),
    NSSortDescriptor(key: "count", ascending: true),
    NSSortDescriptor(key: "name", ascending: true)
]

let dataSource = DATASource(tableView: self.tableView, cellIdentifier: CustomCell.Identifier, fetchRequest: request, mainContext: self.dataStack!.mainContext, sectionName: "firstLetterOfName") { cell, item, indexPath in
}
3lvis commented 8 years ago

Maybe it's obvious, at least it wasn't obvious for me. 😟

3lvis commented 7 years ago

Doing some spring cleaning, please open a new issue if you still want to do this.