How to create a Core Data predicate to test that a relation contains all given objects?

The following predicate could work: [NSPredicate predicateWithFormat:@”(items.@count == %d) AND (SUBQUERY(items, $x, $x IN %@).@count == %d)”, itemSet.count, itemSet, itemSet.count]; The predicate checks first that the number of items is equal to the size of the given itemSet, and then checks that the number of items which are member of itemSet is also equal to … Read more

Xcode 8 generates broken NSManagedObject subclasses for iOS 10

I finally got mine to work. Here is what I did. (Flights is one of my entities) I setup the xcdatamodeld as follows And then the entity as Then I used Editor -> Create NSManagedObject Subclass This creates two files for my flights entity Flights+CoreDataProperties.swift Flights+CoreDataClass.swift I renamed Flights+CoreDataClass.swift to Flights.swift Flights.swift is just import … Read more

What do I have to do to get Core Data to automatically migrate models?

I’ve now found out that this is quite simple – once you know where to look. In my AppDelegate I set-up the NSPersistentStoreCoordinator – and you need to add some options to this to tell it to handle auto-migrate: NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error; _persistentStoreCoordinator = … 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