Fix Main Thread Checker safety issue in DataManager

This commit is contained in:
Cameron Gutman
2017-09-15 00:51:37 -07:00
parent d0d60b8ffc
commit a8d1770871

View File

@@ -19,7 +19,17 @@
- (id) init {
self = [super init];
_appDelegate = [[UIApplication sharedApplication] delegate];
// HACK: Avoid calling [UIApplication delegate] off the UI thread to keep
// Main Thread Checker happy.
if ([NSThread isMainThread]) {
_appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
else {
dispatch_sync(dispatch_get_main_queue(), ^{
_appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
});
}
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_managedObjectContext setPersistentStoreCoordinator:_appDelegate.persistentStoreCoordinator];