0
我是新雨燕3.这里是我的情况:swift3核心数据倒序
我在核心数据保存的一些数据。像1,2,3,4,5...
我想推动他们到tableView
以相反的顺序(5,4,3,2,1)
。
下面是我的一些代码:
记录:
override func viewWillAppear(_ animated: Bool) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let managedContext = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "List")
do {
let result = try managedContext.fetch(request)
Array = result as! [NSManagedObject]
}
catch {
print("some error.....")
}
}
推入细胞
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath as IndexPath)
let item = Array[indexPath.row]
cell.textLabel?.text = item.value(forKey: "data") as? String
return cell
}
我想是这样
Array.reversed()
但Xcode的告诉我结果是联合国用过的。请帮帮我。谢谢。
您也可以在''fetchRequest''中添加'NSSortDescriptor'。 – shallowThought