[英]How to get List from entity in CoreData with all items there is each item appears only once?
In CoreData Model I have"customers" entity with follow columns: custostomer_id , name , city , phone 在CoreData模型中,我具有“客户”实体,其以下各列:custostomer_id,name,city,phone
It has the follow data in it: 其中包含以下数据:
1 Mary Los-Angeles 054-112233
2 John New-York 054-334455
3 Anna Los-Angeles 054-445566
How can I get the List of all cities of customers where each city appears only once. 我如何获得每个城市仅出现一次的所有客户城市列表。 For above example it should be {Los-Angeles, New-Yoirk}.
对于上面的示例,它应该是{Los-Angeles,New-Yoirk}。
This is my code: 这是我的代码:
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];
I mean what should be instead of "???" 我的意思是应该代替“ ???” in NSPredicate definition?
在NSPredicate定义? I tried to write this code also with NSExpression, but still didn't succeeded.
我也尝试使用NSExpression编写此代码,但仍然没有成功。
//将此字符串写为谓词
NSPredicate *predN = [NSPredicate predicateWithFormat:@"SELECT city FROM customers GROUP BY city"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.