Core Data NSPredicate with to-Many Relationship

Core Data predicates with “NOT ANY” do not work (that seem to be a Core Data bug). Actually [NSPredicate predicateWithFormat:@”NOT(ANY couponOwners.userId = %@)”, @”4″]; returns the same result set as [NSPredicate predicateWithFormat:@”ANY couponOwners.userId != %@”, @”4″]; which is of course wrong. As a workaround, you can use a SUBQUERY: [NSPredicate predicateWithFormat:@”SUBQUERY(couponOwners, $c, $c.userId == %@).@count … Read more

Can you do custom animations for UITableView Cell Inserts?

NEWEST SOLUTION (2017-12-12) Adding a Swift 4.0 version of the animate method. It should then be implemented in the same way as the solution below: func animate() { for cell in self.tableView.visibleCells { cell.frame = CGRect(x: self.tableView.frame.size.width, y: cell.frame.origin.y, width: cell.frame.size.width, height: cell.frame.size.height) UIView.animate(withDuration: 1.0) { cell.frame = CGRect(x: 0, y: cell.frame.origin.y, width: cell.frame.size.width, height: … Read more

A NSFetchedResultsController with date as sectionNameKeyPath

This should do the trick for you: – (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *rawDateStr = [[[self.fetchedResultsController sections] objectAtIndex:section] name]; // Convert rawDateStr string to NSDate… NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@”yyyy-MM-dd HH:mm:ss ZZ”]; NSDate *date = [formatter dateFromString:rawDateStr]; // Convert NSDate to format we want… [formatter setDateFormat:@”d MMMM yyyy”]; NSString *formattedDateStr … Read more

NSFetchedResultsController v.s. UILocalizedIndexedCollation

Since you cannot sort on a transient property, the solution I implemented is… Create a string attribute called “sectionKey” for each sortable attribute within each entity in your Core Data model. The sectionKey attribute will be a calculated value derived from a base attribute (e.g., a name or title attribute). It must be persisted because … Read more

NSPredicate: filtering objects by day of NSDate property

Given a NSDate * startDate and endDate and a NSManagedObjectContext * moc: NSPredicate *predicate = [NSPredicate predicateWithFormat:@”(date >= %@) AND (date <= %@)”, startDate, endDate]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:[NSEntityDescription entityForName:@”EntityName” inManagedObjectContext:moc]]; [request setPredicate:predicate]; NSError *error = nil; NSArray *results = [moc executeFetchRequest:request error:&error];

NSFetchedResultsController with relationship not updating

The NSFetchedResultsController is only designed to watch one entity at a time. Your setup, while it makes sense, it a bit beyond what the NSFetchedResultsController is currently capable of watching on its own. My recommendation would be to set up your own watcher. You can base it off the ZSContextWatcher I have set up on … Read more

Changing a managed object property doesn’t trigger NSFetchedResultsController to update the table view

OK, I will explain your problem, then I will let you judge whether it is a bug in FRC or not. If you think it is a bug, then you really should file a bug report with apple. Your fetch result controller predicate is like this: NSString *predicate = [NSString stringWithFormat: @”clockSet.isOpen == YES”]; which … Read more

NSFetchedResultsController with predicate ignores changes merged from different NSManagedObjectContext

Turns out main NSManagedObjectContext didn’ t event fire NSManagedObjectContextObjectsDidChangeNotification for updated objects because it is not done for faulted objects. Generic fix (or keep a track of object IDs that needs this treatment): NSManagedObjectContext *context = [self managedObjectContext]; for(NSManagedObject *object in [[notification userInfo] objectForKey:NSUpdatedObjectsKey]) { [[context objectWithID:[object objectID]] willAccessValueForKey:nil]; } [context mergeChangesFromContextDidSaveNotification:notification]; From NSManagedObject Class … Read more