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
不客氣。 –