0
在CoreData型号我有“客户”实体后续列: custostomer_id,名称,城市,电话如何从CoreData中的实体获取列表,每个项目中只有一个项目出现?
它有它的后续数据:
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写这段代码,但仍然没有成功。
阅读部分https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CoreDataSnippets/Articles/fetchExpressions “读取重复值”。 html http://stackoverflow.com/questions/16424720/nspredicate-fetch-one-of-each-kind –
@Rahul它工作正常,非常感谢。 – Tatiana
不客气。 –