问题
I'm creating a new NSManagedObject and inserting it into a context with concurrency type private queue (so it runs on a background thread).
Right before I save, I call this:
[appDelegate.backgroundMOC obtainPermanentIDsForObjects:
[NSArray arrayWithObject:newObject] error:&error];
Then I save:
[appDelegate.backgroundMOC save:&err];
However, I get a EXC_BAD_ACCESS crash. Looking at the stacktrace, I see:
0 semaphore_wait_trap
7-[NSManagedObjectContentSave:]
I'm guessing the problematic line is the semaphore_wait_trap
, but I'm not sure how that's caused.
If I comment out the line obtainPermanentIDsForObjects
, the problem goes away.
Any ideas?
回答1:
Due to a bug in obtaining object ids (http://openradar.appspot.com/11478919), you need to pass in all newly created objects to -[NSManagedObjectContext obtainPermanentIDsForObjects:error:]
.
来源:https://stackoverflow.com/questions/11315479/getting-thread-errors-when-calling-obtainpermanentidsforobjects