我正在我们的应用中升级到Core Data
并使用.xcmappingmodel
和迁移政策。在此次升级过程中,我的EXC_BAD_ACCESS
AppDelegate
方法获得了persistentStoreCoordinator
:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyApp.sqlite"];
// handle db upgrade
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES};
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
调用堆栈(线程1队列:com.apple.main-thread(串行)):
#0 0x00000001053f29f9 in _propertyAtIndexForEntityDescription ()
#1 0x00000001054449e5 in -[_NSFaultingMutableSet description] ()
#2 0x000000010831fdca in -[NSObject(NSObject) _copyDescription] ()
#3 0x00000001083039ab in __CFStringAppendFormatCore ()
#4 0x0000000108337658 in CFStringAppendFormat ()
#5 0x0000000108332125 in -[__NSDictionaryI __apply:context:] ()
#6 0x00000001083a480d in _CFErrorFormatDebugDescriptionAux ()
#7 0x00000001083a4565 in _CFErrorCreateDebugDescription ()
#8 0x00000001078eacf6 in -[NSError description] ()
#9 0x000000010839ad4a in -[NSArray descriptionWithLocale:indent:] ()
#10 0x000000010831fdca in -[NSObject(NSObject) _copyDescription] ()
#11 0x00000001083039ab in __CFStringAppendFormatCore ()
#12 0x0000000108337658 in CFStringAppendFormat ()
#13 0x00000001083a480d in _CFErrorFormatDebugDescriptionAux ()
#14 0x00000001083a4565 in _CFErrorCreateDebugDescription ()
#15 0x00000001078eacf6 in -[NSError description] ()
#16 0x00000001078463d9 in _NSDescriptionWithLocaleFunc ()
#17 0x0000000108303407 in __CFStringAppendFormatCore ()
#18 0x00000001083008f7 in _CFStringCreateWithFormatAndArgumentsAux2 ()
#19 0x00000001054576d3 in PFLog ()
#20 0x00000001053c316c in -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] ()
#21 0x000000010395a630 in ::-[AppDelegate persistentStoreCoordinator]() at <redacted path>/AppDelegate.mm:522
#22 0x0000000103959e19 in ::-[AppDelegate managedObjectContext]() at <redacted path>/AppDelegate.mm:469
#23 0x0000000103a7351a in -[ZSSCoreDataManager init] at <redacted path>/ZSSCoreDataManager.m:32
#24 0x0000000103a73432 in __35+[ZSSCoreDataManager sharedService]_block_invoke at <redacted path>/ZSSCoreDataManager.m:20
#25 0x000000010c8940cd in _dispatch_client_callout ()
#26 0x000000010c8791fc in dispatch_once_f ()
#27 0x0000000103a733d8 in _dispatch_once [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk/usr/include/dispatch/once.h:75
#28 0x0000000103a733bd in +[ZSSCoreDataManager sharedService] at <redacted path>/ZSSCoreDataManager.m:19
#29 0x0000000103aa44fe in -[ZSSTabBarController updateSettingsBadgeValue] at <redacted path>/ZSSTabBarController.m:49
#30 0x0000000103aa4381 in -[ZSSTabBarController viewDidLoad] at <redacted path>/ZSSTabBarController.m:28
#31 0x00000001098c906d in -[UIViewController loadViewIfRequired] ()
#32 0x00000001098c94a0 in -[UIViewController view] ()
#33 0x0000000109793045 in -[UIWindow addRootViewControllerViewIfPossible] ()
#34 0x0000000109793796 in -[UIWindow _setHidden:forced:] ()
#35 0x00000001097a70a9 in -[UIWindow makeKeyAndVisible] ()
#36 0x0000000109720259 in -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] ()
#37 0x00000001097263b9 in -[UIApplication _runWithMainScene:transitionContext:completion:] ()
#38 0x0000000109723539 in -[UIApplication workspaceDidEndTransaction:] ()
#39 0x000000010e67776b in __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ ()
#40 0x000000010e6775e4 in -[FBSSerialQueue _performNext] ()
#41 0x000000010e67796d in -[FBSSerialQueue _performNextFromRunLoopSource] ()
#42 0x000000010836a311 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#43 0x000000010834f59c in __CFRunLoopDoSources0 ()
#44 0x000000010834ea86 in __CFRunLoopRun ()
#45 0x000000010834e494 in CFRunLoopRunSpecific ()
#46 0x0000000109721db6 in -[UIApplication _run] ()
#47 0x0000000109727f34 in UIApplicationMain ()
#48 0x0000000103a8addf in main at <redacted path>/main.m:14
#49 0x000000010c8e068d in start ()
从我在其他地方读到的内容,这是一个线程问题。我该怎么办?尝试在主线程上创建NSPersistentStoreCoordinator
没有帮助。
在迁移过程中,iOS是否尝试从后台线程调用此命令?我应该锁定线程还是使用performBlockAndWait:
?