Hang on NSManagedObjectContext's save:

2020-07-06 08:03发布

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?

2条回答
ら.Afraid
2楼-- · 2020-07-06 09:01

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-07-06 09:02

Have you tried setting NSError *error to nil?

查看更多
登录 后发表回答