small medium large xlarge

11 Jan 2017, 05:59
Michael Bailey (1 post)

I am trying to run the code for “Threading”, but it crashing when I click the plus button. I don’t get an error messages and when I run the code again the simulator goes blank.

Any help would be appreciated?

11 Jan 2017, 22:15
Marcus S. Zarra (285 posts)

Interesting. What you discovered caused me to file a radar against Core Data :)

The issue is that the app gets blocked on some of the start up code which seems to be blocking the NSPersistentStoreCoordinator and therefore blocking the entire application.

Walking through the start up, the application checks to see if it needs to do a batch update. That check results in zero rows/objects to be updated on launch. The fact that there are no rows to update should mean that the app passes through the bulk update instantaneously.

However that is not the case as you discovered!

What actually happens is that the call to:

NSManagedObjectContext.mergeChanges(fromRemoteContextSave: save, into: contexts)

On line 176 of the PPRDataController blocks … forever!

To get around this problem, a small change needs to be made.

Look at line 230, which currently reads:

self.mergeExternalChanges(resultArray, ofType: NSUpdatedObjectsKey)

and change it to read:

if !resultArray.isEmpty {
  self.mergeExternalChanges(resultArray, ofType: NSUpdatedObjectsKey)

Which will stop the application from trying to merge zero changes.

You must be logged in to comment