gpt4 book ai didi

ios - 重置商店时核心数据崩溃 : 'Object' s persistent store is not reachable from this NSManagedObjectContext's coordinator'

转载 作者:可可西里 更新时间:2023-10-31 23:58:52 32 4
gpt4 key购买 nike

在我用 Swift 编写的 iOS 应用程序中尝试删除核心数据的持久存储时,我遇到了崩溃。流程很简单:当我从应用程序注销时,我删除了商店:

destroyPersistentStoreAtURL

我在应用程序中使用 native Core Data 实现,每次访问托管对象都是使用 performBlock/performBlockAndWait 进行的。此外,这些操作在 NSOperationQueue 中。流程如下:

  1. 退出
  2. cancelAllOperations & waitUntilAllOperationsAreFinished 在执行performBlocks 的队列上
  3. maxConcurrentOperationCount = 1performBlocks
  4. 的队列上
  5. 最后,我在之前的 NSOperationQueue
  6. 中添加了一个销毁持久存储的操作

有时,我会崩溃,但我不明白为什么。据我所知,它与 managedObjectsIDs 和 retain 有关。看一看:

2016-11-14 15:51:58.053 ******[3912:179074] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca0f34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010c05321e objc_exception_throw + 48
2 CoreData 0x000000010c5683b2 _PFRetainedObjectIDCore + 1074
3 CoreData 0x000000010c5507fc -[NSManagedObjectContext objectWithID:] + 668
4 CoreData 0x000000010c590264 _faultBatchAtIndex + 1524
5 CoreData 0x000000010c59217a -[_PFBatchFaultingArray retainedObjectAtIndex:] + 74
6 CoreData 0x000000010c592262 -[_PFBatchFaultingArray objectAtIndex:] + 50
7 CoreData 0x000000010c67d9de __72-[NSFetchedResultsController(PrivateMethods) _computeSectionInfo:error:]_block_invoke + 190
8 CoreData 0x000000010c55adc7 developerSubmittedBlockToNSManagedObjectContextPerform + 199
9 CoreData 0x000000010c55ac7f -[NSManagedObjectContext performBlockAndWait:] + 255
10 CoreData 0x000000010c67d3b6 -[NSFetchedResultsController(PrivateMethods) _computeSectionInfo:error:] + 694
11 CoreData 0x000000010c681d75 __82-[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:]_block_invoke + 1077
12 CoreData 0x000000010c55adc7 developerSubmittedBlockToNSManagedObjectContextPerform + 199
13 CoreData 0x000000010c55ac7f -[NSManagedObjectContext performBlockAndWait:] + 255
14 CoreData 0x000000010c681927 -[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:] + 119
15 CoreFoundation 0x000000010c9ad19c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
16 CoreFoundation 0x000000010c9ad09b _CFXRegistrationPost + 427
17 CoreFoundation 0x000000010c9ace02 ___CFXNotificationPost_block_invoke + 50
18 CoreFoundation 0x000000010c96fea2 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
19 CoreFoundation 0x000000010c96ef3b _CFXNotificationPost + 667
20 Foundation 0x000000010bb1b0ab -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
21 CoreData 0x000000010c5432b0 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 704
22 CoreData 0x000000010c562b50 -[NSManagedObjectContext(_NSInternalNotificationHandling) _processChangedStoreConfigurationNotification:] + 2976
23 CoreData 0x000000010c5d97ed __95-[NSManagedObjectContext(_NSInternalNotificationHandling) _sendOrEnqueueNotification:selector:]_block_invoke + 109
24 CoreData 0x000000010c55adc7 developerSubmittedBlockToNSManagedObjectContextPerform + 199
25 libdispatch.dylib 0x000000010e0250cd _dispatch_client_callout + 8
26 libdispatch.dylib 0x000000010e0058d6 _dispatch_main_queue_callback_4CF + 406
27 CoreFoundation 0x000000010c9d34f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
28 CoreFoundation 0x000000010c998f8d __CFRunLoopRun + 2205
29 CoreFoundation 0x000000010c998494 CFRunLoopRunSpecific + 420
30 GraphicsServices 0x000000010f5d0a6f GSEventRunModal + 161
31 UIKit 0x000000010a050964 UIApplicationMain + 159
32 ****** 0x000000010817e932 main + 114
33 libdyld.dylib 0x000000010e07168d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

非常感谢任何帮助!

最佳答案

您需要重置在此操作之前使用的 managedObjectContext

调用managedObjectContext.reset()

关于ios - 重置商店时核心数据崩溃 : 'Object' s persistent store is not reachable from this NSManagedObjectContext's coordinator',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40591169/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com