edc1591
edc1591

Reputation: 10182

Hang on NSManagedObjectContext's save:

For some reason sometimes my app will just hang with the following code:

NSError *error;
if (![self.managedObjectContext save:&error]) {
     NSLog(@"Couldn't save: %@", [error localizedDescription]);
}

It doesn't always hang, just sometimes. If I break on all exceptions then Xcode will break on the save call, but if I turn off breakpoints it will just hang forever, no crashes or anything.

Any ideas?

Upvotes: 9

Views: 2385

Answers (2)

Piotr Byzia
Piotr Byzia

Reputation: 3423

Hanging on anything that uses ManagedObjectContext is a sign of a deadlock. Either use NSLocking protocol or create a new MOC for each thread and synchronize them.

Another useful doc from Apple -> Concurrency with Core Data

Upvotes: 6

dman
dman

Reputation: 146

Have you tried setting NSError *error to nil?

Upvotes: -3

Related Questions