如何将sql查询替换为Core Data获取请求? 这是查询:
NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM diario GROUP BY strftime('%%d', date_time) ORDER BY date_time"];
答案 0 :(得分:0)
您必须使用NSPredicate
类和NSSortDescriptor
对结果进行排序。那将是这样的:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"diario" inManagedObjectContext:moc];
NSPredicate *predicate = [NSPredicate predicateWithFormat:/*Your predicate here*/];
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"date_time" ascending:YES];
fetchRequest.entity = entity;
fetchRequest.predicate = predicate;
fetchRequest.sortDescriptor = sort;