Skip to content

Instantly share code, notes, and snippets.

@akisute
Created November 25, 2012 03:57
Show Gist options
  • Save akisute/4142337 to your computer and use it in GitHub Desktop.
Save akisute/4142337 to your computer and use it in GitHub Desktop.
[super viewWillAppear:animated];
NSManagedObjectContext *context = [NSManagedObjectContext MR_contextForCurrentThread];
// ここで、FEUnitはFEClanに対してclanというrelationを持っているとする
// FEClanはFEUnitに対してunitsというrelationを持っているとする
// NSManagedObjectIDで検索
// Property clanID must be permanent since a temporary ID cannot handle this query
self.fetchedResultsController = [FEUnit MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"clan == %@", self.clanID]
sortedBy:@"firstName"
ascending:YES
delegate:nil
inContext:context];
NSAssert(self.clanID, @"Property clanID must be set before view will appear.");
NSAssert(!self.clanID.isTemporaryID, @"Property clanID must be a permanent ID.");
// NSManagedObject直指定でもOK、これだとIDがテンポラリだろうがなんだろうが問題ない
self.fetchedResultsController = [FEUnit MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"clan == %@", self.clan]
sortedBy:@"firstName"
ascending:YES
delegate:nil
inContext:context];
// NULL指定も可能なはず
self.fetchedResultsController = [FEUnit MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"clan == NULL"]
sortedBy:@"firstName"
ascending:YES
delegate:nil
inContext:context];
// 1:Nで逆指定
self.fetchedResultsController = [FEClan MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"units in %@", self.someUnits]
sortedBy:@"name"
ascending:YES
delegate:nil
inContext:context];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment