根据价格对coredata进行排序

时间:2018-05-29 06:21:07

标签: ios swift sorting core-data

我在offerPrice类型的coredata中有一个名为String的属性。现在点击一个按钮,我想按照这个offerprice按升序对coredata数组中的所有元素进行排序。

我可以根据names这样排序......

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "NewProduct")

let sort = NSSortDescriptor(key: "name", ascending: false)
request.sortDescriptors = [sort]

do {
    newProdDetails2 = try context.fetch(request) as! [NewProduct]
    tableview.reloadData()
   } catch {
      print("Fetching Failed")
 }

在这个地方,key: "name"我尝试在offerPrice的基础上对name而不是offerPrice进行排序。但它不起作用..

0 个答案:

没有答案
相关问题