Ios NSPredicate按字母顺序提取CoreData中的记录

Ios NSPredicate按字母顺序提取CoreData中的记录,ios,sql,iphone,core-data,nspredicate,Ios,Sql,Iphone,Core Data,Nspredicate,我正试图从一个实体中获取记录,这些记录超过5000条。因此,我希望使用字母排序(name参数)来获取记录,而不是在结果数组上使用NSSortDescriptor进行排序 是否有任何谓词可以按字母顺序对fetech记录进行排序。不,不能使用NSPredicate对数组进行排序 The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for

我正试图从一个实体中获取记录,这些记录超过5000条。因此,我希望使用字母排序(name参数)来获取记录,而不是在结果数组上使用NSSortDescriptor进行排序


是否有任何谓词可以按字母顺序对fetech记录进行排序。

不,不能使用NSPredicate对数组进行排序

The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

NSFetchRequest*fetchRequest
中设置
NSSortDecriptor
,就像使用任何谓词一样

[fetchRequest setSortDescriptors:@[[[NSSortSDescriptor alloc] initWithKey:@"name parameter" ascending:YES]]];
这意味着您的请求在提取时已经按照您的要求进行了排序

正如Kaszas已经说过的,NSPredicate不是用于排序,而是用于过滤

希望这对Swift 4.0有所帮助

let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]