如何使用该受管对象的date属性对NSFetchRequest进行排序.那么它创建一个数组,其日期顺序?
这是我的代码到目前为止
var request : NSFetchRequest = NSFetchRequest(entityName: "History"); request.predicate = NSPredicate(format: "counts = %@",true) request.sortDescriptors = [???] <- What should I put here? var results : [NSManagedObject] = context.executeFetchRequest(request,error: nil) as [NSManagedObject]
// newest first request.sortDescriptors = [NSSortDescriptor(key: "date",ascending: false)]
注意:您不需要:[NSManagedObject]如果您已经具有[NSManagedObject].当您使用NSFetchRequest的工厂方法时,您不需要:NSFetchRequest.