Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making com.apple.CoreData.ConcurrencyDebug 1 work

Tags:

ios

core-data

I am trying to migrate some code to use an NSManagedObjectContext with NSPrivateQueueConcurrencyType.

I'm sometimes getting very odd errors after saving the context to its parent, and then saving the parent. I'm wondering if these are due to be not using the NSPrivateQueueConcurrencyType context correctly.

I've turned on -com.apple.CoreData.ConcurrencyDebug 1 to try to debug this. I'm pretty sure that this is not working however. If I perform operations on managed object context or change its objects without using performBlock:, I don't get an error or a throw.

Here's how I've set up the scheme's arguments:Schema Edit. I've also tried it without the leading -.

Any idea what I'm doing wrong?

like image 674
Benjohn Avatar asked Jul 13 '15 19:07

Benjohn


1 Answers

Working with XCode 8.x and iOS 10.x, I wanted to provide a streamlined answer for anyone wanting to implement this now.

You will first need to modify the scheme for your app:

enter image description here

Once you select Scheme, select Edit Scheme which should appear near the bottom of your list: enter image description here

When opened, make sure that you have Run selected and choose Arguments. You will want to copy the following values in:

  • -com.apple.CoreData.ConcurrencyDebug 1
  • -com.apple.CoreData.Logging.stderr 1

Your screen should look like this: enter image description here

After launching the app, you should see this appear in your console now when those options are enabled:

CoreData: annotation: Core Data multi-threading assertions enabled.

And when you run into an exception generated by this, you will likely see this:

CoreData`+[NSManagedObjectContext Multithreading_Violation_AllThatIsLeftToUsIsHonor]:

You can return to the scheme editor and disable this logging as needed to prevent exceptions in the future.

like image 87
CodeBender Avatar answered Oct 11 '22 20:10

CodeBender