【发布时间】:2018-01-30 10:08:08
【问题描述】:
现在我使用这个函数来获取我的UITableView,它工作正常,但我想通过"dataUltimei" 对它进行排序,这是一个日期(例如:07.08.2017)。我不知道为什么,但它没有对表格进行排序。这是我的代码:
func fetch() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedObjectContext = appDelegate.persistentContainer.viewContext
let sortDescriptor = NSSortDescriptor(key: "dataUltimei", ascending: true)
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:"Contact")
fetchRequest.sortDescriptors = [sortDescriptor]
do {
contacts = try managedObjectContext.fetch(fetchRequest) as! [NSManagedObject]
} catch let error as NSError {
print("Could not fetch. \(error)")
}
}
【问题讨论】:
-
你在使用 fetchResultViewController 吗?
-
是的,我正在使用 fetchResultViewController
标签: ios swift uitableview core-data swift3