你好我的应用程序显示了按国家/地区分组的城市(街道)列表。 当我保存一条新街道时,它看起来像这样:
Country -> USA
City-> New York
street-> timeSqaure
当我保存另一条街道时:
Country -> USA
City-> New York
street-> 233 street 330 west
我的TableView重复了城市Screenshot
如何将重复的城市过滤到一个独特的城市。
我的fetch看起来像这样:
-(void) performFetch
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *context = [app managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Country" inManagedObjectContext:context];
[request setEntity:entity];
NSSortDescriptor *sort1 = [[NSSortDescriptor alloc] initWithKey:@"country" ascending:YES];
NSArray *sortArray = [NSArray arrayWithObjects:sort1, nil];
[request setSortDescriptors:sortArray];
NSError *error;
self.fetchedResultsController =[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:@"country" cacheName:nil];
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"failure: %@", [error localizedDescription]);
}
}
答案 0 :(得分:0)