Post

Replies

Boosts

Views

Activity

upgraded to iOS 14 - infinite loop in InsertNewObject + diffableDataSource
So.... I'm touching a project I haven't looked at in 7 months, which was an attempt to use CloudKit CoreData and Diffable Data Sources with a split view controller from the template. I'm running it on latest everything now and it is causing an infinite loop in the saving context part of InsertNewObject, and the FetchResult Controller delegate update snapshot. It keeps adding tableviewcells. Yes I'm still using Objective C. I thought it would be interesting to try to make everything work with the new Diffable Data Source. I tried deleting all CloudKit records and that didn't help. Not sure what has changed in the last 7 months but I'm pretty sure the project worked the last time I touched it. Here's the code - it's looping somewhere in the bold section: (void)insertNewObject:(id)sender {     NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];     TaskCategory *newTaskCategory = [[TaskCategory alloc] initWithContext:context];     // If appropriate, configure the new managed object.     newTaskCategory.uniqueID = [NSUUID UUID];     newTaskCategory.orderInSection = [[self.fetchedResultsController sections] count];     newTaskCategory.categoryName = @"";     Task *newTask = [[Task alloc]initWithContext:context];     newTask.uniqueID = [NSUUID UUID];     newTask.orderInSection = 0;     newTask.taskName = @"";     newTask.pointValue = 1;     [newTaskCategory addTasksObject:newTask];     // Save the context.     NSError *error = nil;     if(![context obtainPermanentIDsForObjects:@[newTask, newTaskCategory] error:&error]){           NSLog(@"Unresolved error %@, %@", error, error.userInfo);            abort();       }     if (![context save:&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();     } } (void)controller:(NSFetchedResultsController *)controller didChangeContentWithSnapshot:(NSDiffableDataSourceSnapshot<NSString *,NSManagedObjectID *> *)snapshot {     if (self.masterTableView.window)     {         [self.tableData applySnapshot:snapshot animatingDifferences:YES];     } } The only thing logging at this time is CloudKit stuff: CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2092): <NSCloudKitMirroringDelegate: 0x600003c94c30>: Observed context save: <NSPersistentStoreCoordinator: 0x600002cd7db0> - <NSManagedObjectContext: 0x600003c94d00> CoreData: CloudKit: CoreData+CloudKit: -[PFCloudKitExporter exportIfNecessary]_block_invoke_2(153): <PFCloudKitExporter: 0x6000024ec870>: Found 0 objects needing export. CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2092): <NSCloudKitMirroringDelegate: 0x600003c94c30>: Observed context save: <NSPersistentStoreCoordinator: 0x600002cd7db0> - <NSManagedObjectContext: 0x600003cca490> CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _exportFinishedWithResult:exporter:](1161): Finished export: <PFCloudKitExporter: 0x6000024ec870> CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _finishedRequest:withResult:](2483): Finished request: <NSCloudKitMirroringExportRequest: 0x6000009a2100> 0A0EEAA5-54E0-41BE-8C89-5FFB1A3CD045 with result: <NSCloudKitMirroringResult: 0x6000007fa3c0> success: 1 madeChanges: 0 error: (null) CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _scheduleAutomatedExportWithLabel:activity:completionHandler:]_block_invoke(2581): <NSCloudKitMirroringDelegate: 0x600003c94c30> - Finished automatic export - ExportActivity - with result: <NSCloudKitMirroringResult: 0x6000007fa3c0> success: 1 madeChanges: 0 error: (null) CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](2496): Finished request '<NSCloudKitMirroringExportRequest: 0x6000009a2100> 0A0EEAA5-54E0-41BE-8C89-5FFB1A3CD045' with result: <NSCloudKitMirroringResult: 0x6000007fa3c0> success: 1 madeChanges: 0 error: (null) CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](2452): <NSCloudKitMirroringDelegate: 0x600003c94c30>: Checking for pending requests. CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(2468): <NSCloudKitMirroringDelegate: 0x600003c94c30>: No more requests to execute.
0
0
776
Jan ’21