で働いていない私は次のことを理解しようと時間を費やしてい...コアデータ - 明確な結果がfetchedResultsController
私は私の価値の明確なセットを返さない私のiPhoneアプリでは、次のコアデータfetchResultsControllerを持っています私のコードでは、次の...
// Only distinct values
[fetchRequest setReturnsDistinctResults:YES];
を設定するにもかかわらず、次は全体fetchResultController ...
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"CardMessage"inManagedObjectContext:self.managedObjectContext]];
// Set the properties to fetch
NSArray *propertiesToFetch = [[NSArray alloc] initWithObjects:@"category", nil];
[fetchRequest setPropertiesToFetch:propertiesToFetch];
// Only distinct values
[fetchRequest setReturnsDistinctResults:YES];
// Order the output
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"category" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __fetchedResultsController;
}
素早い応答をありがとうが、エンティティ内のすべての行が返されます – rs2000
NSSetを使用できます。上記を参照。 – Mundi
乾杯はNSSetを使用しなければなりませんでした...なぜ少し混乱[fetchRequest setReturnsDistinctResults:YES]; did not work ... PS ...一般的なフェッチリクエストとして動作するようです... – rs2000