这是我想为Core Data
撰写的查询的SQL版本:
SELECT ROUNDNAME
FROM MODELSCHEDULEFIXTURE
GROUP BY ROUNDNAME
ORDER BY MATCHID
我使用了以下代码,但应用程序崩溃了。
-(NSArray *)getRound
{
NSManagedObjectContext * context = ((AFLAppDelegate *)[[UIApplication sharedApplication] delegate] ).managedObjectContext;
NSFetchRequest *fetch = [NSFetchRequest new];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"modelschedulefixture" inManagedObjectContext:context];
NSAttributeDescription* statusDesc = [entity.attributesByName objectForKey:@"roundName"];
[fetch setPropertiesToFetch:[NSArray arrayWithObjects:statusDesc, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:statusDesc]];
[fetch setResultType:NSDictionaryResultType];
NSError *error = nil;
NSArray *array= [context executeFetchRequest:fetch error:&error];
return array;
}
答案 0 :(得分:1)
试试。
-(NSArray *)getRound{
NSArray *array=nil;
NSManagedObjectContext * context = ((AFLAppDelegate *)[[UIApplication sharedApplication] delegate] ).managedObjectContext;
NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@"modelschedulefixture"];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"modelschedulefixture" inManagedObjectContext:context];
NSSortDescriptor *sortDescreptorRound =[[NSSortDescriptor alloc]initWithKey:@"matchid" ascending:YES];
[fetch setSortDescriptors:[NSArray arrayWithObject:sortDescreptorRound]];
NSAttributeDescription* statusDesc = [entity.attributesByName objectForKey:@"roundname"];
[fetch setPropertiesToFetch:[NSArray arrayWithObjects:statusDesc, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:statusDesc]];
[fetch setResultType:NSDictionaryResultType];
NSError *error = nil;
array = [context executeFetchRequest:fetch error:&error];
return array;
}