Ios 迁移期间核心数据持久存储协调器EXC_错误访问

Ios 迁移期间核心数据持久存储协调器EXC_错误访问,ios,objective-c,multithreading,core-data,core-data-migration,Ios,Objective C,Multithreading,Core Data,Core Data Migration,我正在我们的应用程序中升级到核心数据,并使用.xcmappingmodel和迁移策略。在此升级过程中,我在我的AppDelegatepersistentStoreCoordinator方法中获得了EXC\u BAD\u访问权限: - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _persistent

我正在我们的应用程序中升级到
核心数据
,并使用
.xcmappingmodel
和迁移策略。在此升级过程中,我在我的
AppDelegate
persistentStoreCoordinator
方法中获得了
EXC\u BAD\u访问权限

- (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(串行)):

#u propertyAtIndexForEntityDescription()中的0 0x00000001053f29f9
#1 0x00000001054449e5 in-[\n故障可变表集描述]()
#2 0x000000010831fdca in-[NSObject(NSObject)\u copyDescription]()
#3 0x00000001083039ab位于CFStringAppendFormatCore()中
#4 0x0000000108337658,CFStringAppendFormat()
#5 0x0000000108332125英寸-[\uuuuuuuu-nsyi\uuuuuu-apply:上下文:]()
#6 0x00000001083a480d,位于\u CFErrorFormatDebugDescriptionAux()中
#7 0x00000001083a4565英寸\u CFErrorCreateDebugDescription()
#8 0x00000001078eacf6英寸-[N错误说明]()
#9 0x000000010839ad4a in-[NSArray description with locale:indent:()
#10 0x000000010831fdca in-[NSObject(NSObject)\u copyDescription]()
#11 0x00000001083039ab位于CFStringAppendFormatCore()中
#CFStringAppendFormat()格式的12 0x0000000108337658
#13 0x00000001083a480d在_CFErrorFormatDebugDescriptionAux()中
#14 0x00000001083a4565英寸\u CFErrorCreateDebugDescription()
#15 0x00000001078eacf6英寸-[N错误说明]()
#16 0x00000001078463d9,在描述中使用localefunc()
#17 0x0000000108303407英寸CFStringAppendFormatCore()
#18 0x00000001083008f7英寸\u CFStringCreateWithFormatAndArgumentsAux2()
#PFLog中的19 0x00000001054576d3()
#20 0x00000001053c316c in-[NSPersistentStoreCoordinator addPersistentStoreWithType:配置:URL:选项:错误:()
#21 0x000000010395a630英寸:-[AppDelegate persistentStoreCoordinator]()位于/AppDelegate.mm:522
#22 0x0000000103959e19 in::-[AppDelegate managedObjectContext]()位于/AppDelegate.mm:469
#23 0x0000000103a7351a in-[ZSSCoreDataManager init]at/ZSSCoreDataManager.m:32
#24 0x0000000103a73432 in_uuu35+[ZSSCoreDataManager sharedService]u block_u调用/ZSSCoreDataManager.m:20
#25 0x000000010c8940cd在调度客户调用()中
#26 0x000000010c8791fc在调度中一次
#27 0x0000000103a733d8 in_dispatch_once[内联]at/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/sdk/iPhoneSimulator10.2.sdk/usr/include/dispatch/once.h:75
#28 0x0000000103a733bd在+[ZSSCoreDataManager共享服务]中位于/ZSSCoreDataManager.m:19
#29 0x0000000103aa44fe in-[zsThankarcontroller updateSettingsBadgeValue]位于/zsThankarcontroller.m:49
#30 0x0000000103aa4381 in-[zsStucharController viewDidLoad]at/zsStucharController.m:28
#31 0x00000001098c906d in-[UIViewController loadViewIfRequired]()
#32 0x00000001098c94a0在-[UIViewController视图]()
#33 0x0000000109793045 in-[UIWindow AddRootViewControllerServiceWifPossible]()
#34 0x0000000109793796英寸-[UIWindow\u setHidden:强制:]()
#35 0x00000001097a70a9英寸-[UIWindow makeKeyAndVisible]()
#36 0x0000000109720259 in-[UIApplication\u callInitializationDelegatesForMainScene:transitionContext:()
#37 0x00000001097263b9 in-[UIApplication\u在主场景中运行:transitionContext:completion:()
#38 0x0000000109723539 in-[UIApplication workspaceDidEndTransaction:]()
#39 0x000000010e67776b输入FBSSERIALQUEUE正在调用输出到块
#40 0x000000010e6775e4 in-[FBSSerialQueue_performNext]()
#41 0x000000010e67796d in-[FBSSerialQueue _performNextFromRunLoopSource]()
#42 0x000000010836a311 in运行循环正在调用OUT执行函数
#43 0x000000010834f59c在\uuu CFRunLoopDoSources0()中
#44 0x000000010834ea86在\uuuu CFRunLoopRun()中
#CFRunLoopRunSpecific()中的45 0x000000010834e494
#46 0x0000000109721db6 in-[UIApplication_run]()
#UIApplicationMain()中的47 0x0000000109727f34
#48 0x0000000103a8addf位于/main.m:14的干管中
#49 0x000000010c8e068d处于启动状态()
从我在别处读到的内容来看,这是一个线程问题。我在这里该怎么办?试图在主线程上创建
NSPersistentStoreCoordinator
没有帮助


在迁移过程中,iOS是否尝试从后台线程调用此功能?我应该锁定线程还是使用
performBlockAndWait:

可以共享调用堆栈吗?它是在后台线程中吗?@Davewston刚刚添加了它。它似乎在试图生成一条返回给您的错误消息时崩溃了,但很难确切地说出到底发生了什么。您可以检查的一件事是确保您的模型对象都继承自
NSManagedObject
。如果您仍然存在此问题,是否可以私下共享该项目?@davewston不,我将无法私下共享该项目。但是我很乐意提供更多关于Stackoverflow的细节。你能分享一下调用堆栈吗?它是在后台线程中吗?@Davewston刚刚添加了它。它似乎在试图生成一条返回给您的错误消息时崩溃了,但很难确切地说出到底发生了什么。您可以检查的一件事是确保您的模型对象都继承自
NSManagedObject
。如果您仍然存在此问题,是否可以私下共享该项目?@davewston不,我将无法私下共享该项目。但我很乐意提供更多关于Stackoverflow的细节。
#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 ()