我使用'sortdescriptor'来获取'nsmutablearray',它按创建日期排序,但问题是它没有按谓词过滤。我想同时应用sort和filter.i尝试过以下
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: entityName)
let sort = NSSortDescriptor(key: "date", ascending: false)
let pre:NSPredicate = NSPredicate(format: "id == %d", 100)
fetchRequest.predicate = pre
fetchRequest.sortDescriptors = [sort]
答案 0 :(得分:0)
你可以试试这个: -
change <Message> to your entityModel
let fetchRequest = NSFetchRequest<Message>.init(entityName: "Message")
fetchRequest.sortDescriptors = [NSSortDescriptor.init(key: "date", ascending: false)]
let predicate = NSPredicate.init(format: "id = %@","100")
fetchRequest.predicate = predicate