【发布时间】:2013-09-28 07:11:08
【问题描述】:
在 CoreData 模型中,我有“客户”实体和后续列: customer_id , 姓名 , 城市 , 电话
里面有以下数据:
1 Mary Los-Angeles 054-112233
2 John New-York 054-334455
3 Anna Los-Angeles 054-445566
如何获取每个城市只出现一次的所有客户城市的列表。对于上面的例子,它应该是 {Los-Angeles, New-Yoirk}。
这是我的代码:
AppDelegate * delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = delegate.managedObjectContext ;
NSEntityDescription *entityDescN = [NSEntityDescription entityForName:@"customers" inManagedObjectContext:context];
NSFetchRequest *requestN = [[NSFetchRequest alloc] init];
[requestN setEntity:entityDescN ];
NSPredicate *predN = [NSPredicate predicateWithFormat:@"?????????????"];
[requestN setPredicate:predN];
NSArray * objectsN = [context executeFetchRequest: requestN error:&error];
我的意思是应该用什么来代替“???”在 NSPredicate 定义中? 我也试过用 NSExpression 写这段代码,但还是没有成功。
【问题讨论】:
-
@Rahul 工作正常,非常感谢。