CoreData获取PermanentIDsForObjects与Xcode 6 Beta 6崩溃

时间:2014-08-27 11:58:31

标签: ios objective-c core-data magicalrecord xcode6-beta6

我在这个方法中使用MagicalRecord并为实体导入数据:

+(void)importEnduserOnBackgroundFromResponse:(id)responseObject
                                     success:(void (^)(QNEnduser *provider))success
                                  andFailure:(void (^)(NSError *error))failure
{
    __block NSManagedObjectID *enduserID;
    __block NSError *importError;
    [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        QNEnduser *enduser = [QNEnduser MR_importFromObject:enduserDict inContext:localContext];

        [localContext obtainPermanentIDsForObjects:localContext.insertedObjects.allObjects error:&importError];
        enduserID = enduser.objectID;
    } completion:^(BOOL successFlag, NSError *saveError) {
        // Check for errors (importError and saveError), if no errors import the entity in the main context and call the success block
        QNEnduser *newEnduser = (QNEnduser*)[[NSManagedObjectContext MR_defaultContext] objectWithID:enduserID];
    }];
}

请注意,我已在完成块中删除了一些代码,因为它对此问题并不重要。

Xcode 5 中,此代码有效。但是在 Xcode 6 Beta 6 中,它会在[localContext obtainPermanentIDsForObjects:localContext.insertedObjects.allObjects error:&importError];

引发异常

我发现了类似的问题(Getting thread errors when calling obtainPermanentIDsForObjectsCore Data: Do child contexts ever get permanent objectIDs for newly inserted objects?),但它们比较旧,而且他们的解决方案在我的情况下不起作用,正如您所看到的,我已经尝试获取永久ID所有插入的对象(即使无论如何都没关系,没有其他插入的对象)。

有没有其他人遇到过这个问题,它是否是测试版6中已知的Bug并且是否有一个已知的workarround?或者毕竟是我的错?

修改

不知怎的,我无法获得异常 - 我在Xcode中设置了异常断点,但是当我在坏行周围放置一个@try/@catch时,没有任何东西被捕获。

在异常断点处停止时,这是回溯:

* thread #4: tid = 0x2f2a0, 0x0000000103f19973 libobjc.A.dylib`objc_exception_throw, queue = 'NSManagedObjectContext Queue', stop reason = breakpoint 1.3
  frame #0: 0x0000000103f19973 libobjc.A.dylib`objc_exception_throw
  frame #1: 0x0000000102333dd2 CoreData`-[NSPersistentStoreCoordinator(_NSInternalMethods) obtainPermanentIDsForObjects:error:] + 1458
  frame #2: 0x00000001023aa16d CoreData`__99-[NSManagedObjectContext(_NestedContextSupport) _parentObtainPermanentIDsForObjects:context:error:]_block_invoke + 1037
  frame #3: 0x0000000104f5772d libdispatch.dylib`_dispatch_client_callout + 8
  frame #4: 0x0000000104f465d0 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 57
  frame #5: 0x000000010233df92 CoreData`_perform + 114
  frame #6: 0x00000001023a9bde CoreData`-[NSManagedObjectContext(_NestedContextSupport) _parentObtainPermanentIDsForObjects:context:error:] + 446
  frame #7: 0x0000000102333592 CoreData`-[NSManagedObjectContext obtainPermanentIDsForObjects:error:] + 498
* frame #8: 0x000000010206fc28 QonnectAPIPod`__75+[QNImportHelper importEnduserOnBackgroundFromResponse:success:andFailure:]_block_invoke(.block_descriptor=<unavailable>, localContext=0x00007fd078dd8d60) + 568 at QNImportHelper.m:129
  frame #9: 0x0000000102142abd QonnectAPIPod`__51+[MagicalRecord(.block_descriptor=0x00007fd078d026b0) saveWithBlock:completion:]_block_invoke + 25 at MagicalRecord+Actions.m:28
  frame #10: 0x00000001023a461e CoreData`developerSubmittedBlockToNSManagedObjectContextPerform_privateasync + 78
  frame #11: 0x0000000104f5772d libdispatch.dylib`_dispatch_client_callout + 8
  frame #12: 0x0000000104f46dcf libdispatch.dylib`_dispatch_queue_drain + 481
  frame #13: 0x0000000104f46b94 libdispatch.dylib`_dispatch_queue_invoke + 112
  frame #14: 0x0000000104f479fc libdispatch.dylib`_dispatch_root_queue_drain + 81
  frame #15: 0x0000000104f47d12 libdispatch.dylib`_dispatch_worker_thread2 + 40
  frame #16: 0x00000001052ebef8 libsystem_pthread.dylib`_pthread_wqthread + 314
  frame #17: 0x00000001052eefb9 libsystem_pthread.dylib`start_wqthread + 13

0 个答案:

没有答案