【发布时间】:2014-03-19 07:02:55
【问题描述】:
这是我想为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;
}
【问题讨论】:
-
可能重复 stackoverflow.com/questions/4865686/… 看看那里发布的链接。