Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Store your parent object somewhere in your child view controller, typically it should be like </p> <p>.h file:</p> <pre><code>@property (nonactomic, strong) ParentObject *parentObject; </code></pre> <p>.m file</p> <pre><code>- (id)initWithObject:(ParentObject *)parent { … _parentObject = parent; … } </code></pre> <p>then fetching: (you should have <code>@property (nonatomic, strong) NSFecthedResultsController *fetchedResultController</code>)</p> <pre><code>- (NSFetchedResultsController*)fetchedResultController { if (_fetchedResultController) { return _fetchedResultController; } NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:NSStringFromClass([ChildObject class])]; [request setEntity:entity]; NSSortDescriptor *sortDescription = [NSSortDescriptor sortDescriptorWithKey:@"sortOrder" ascending:YES]; [request setSortDescriptors:@[sortDescription]]; request.predicate = [NSPredicate predicateWithFormat:@"(parent == %@)", self.parentObject]; NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:[NSManagedObjectContext mainThreadContext] sectionNameKeyPath:nil cacheName:nil]; controller.delegate = self; _fetchedResultController = controller; return _fetchedResultController; } </code></pre> <p>then implement method</p> <pre><code>- (void)performFetch { NSError *error = nil; [self.fetchedResultController performFetch:&amp;error]; if (![self.fetchedResultController performFetch:&amp;error]) { [self showAlertWithError:error]; } else { [self.tableView reloadData]; } } </code></pre> <p>thats it basically you will receive all child objects you need sorted and filtered by predicate</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload