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