仅在 iOS 14 中崩溃核心数据

Posted

技术标签:

【中文标题】仅在 iOS 14 中崩溃核心数据【英文标题】:Crash Core Data only in iOS 14 【发布时间】:2020-09-21 16:29:53 【问题描述】:

我在一个使用 CoreData 的应用程序上工作,在 ios 13 和 iOS 14 上一切正常,具有不同的 Xcode 测试版。但自从 Apple 发布了 iOS 14 和 Xcode 12 的官方版本后,当我尝试从 CoreData 获取一些对象时,我遇到了崩溃。

guard let customers = Customer.mr_findAllSorted(by: "login", ascending: true) as? [Customer] else return

控制台输出:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings 
.'

当我尝试使用断点从控制台日志打印对象时,我有一个对象的内存地址,但是当我尝试打印该对象的一些值时,我遇到了这个错误:

error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated

error: Execution was interrupted, reason: internal ObjC exception breakpoint(-5)..
The process has been returned to the state before expression evaluation.

自从正式版以来,有没有人处理过这类错误?

提前感谢您的帮助。

【问题讨论】:

是“客户”NSManageObject 类型吗?如果是,请检查是否有故障 【参考方案1】:

我们在我们的应用中也看到了这一点。它只能在 iOS 14 和 Xcode 12.0.1 中的最新 SDK 上重现,但我们还没有任何解决方案或答案来解释为什么会发生这种情况。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings 
.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff2043a126 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48
    2   Foundation                          0x00007fff2088bedc -[NSVariableExpression _expressionWithSubstitutionVariables:] + 0
    3   Foundation                          0x00007fff2075ac7b -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 264
    4   CoreData                            0x00007fff2511ec68 -[NSDictionaryStoreMap handleFetchRequest:] + 481
    5   CoreData                            0x00007fff2511dfd2 -[NSMappedObjectStore executeFetchRequest:withContext:] + 230
    6   CoreData                            0x00007fff251e10a2 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.797 + 3219
    7   CoreData                            0x00007fff251d988d __55-[NSPersistentStoreCoordinator _routeHeavyweightBlock:]_block_invoke + 55
    8   CoreData                            0x00007fff251edf0a gutsOfBlockToNSPersistentStoreCoordinatorPerform + 182
    9   libdispatch.dylib                   0x000000010a6b0a88 _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x000000010a6bfcac _dispatch_lane_barrier_sync_invoke_and_complete + 132
    11  CoreData                            0x00007fff251d9492 _perform + 169
    12  CoreData                            0x00007fff251d9740 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 172
    13  CoreData                            0x00007fff250d640e -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1684
    14  CoreData                            0x00007fff250d49c2 -[NSManagedObjectContext executeFetchRequest:error:] + 885
    15  CoreData                            0x00007fff251a9d7f -[NSManagedObjectContext _parentObjectsForFetchRequest:inContext:error:] + 477
    16  CoreData                            0x00007fff251aa774 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 603
    17  CoreData                            0x00007fff25109de8 internalBlockToNSManagedObjectContextPerform + 89
    18  libdispatch.dylib                   0x000000010a6b0a88 _dispatch_client_callout + 8
    19  libdispatch.dylib                   0x000000010a6bfcac _dispatch_lane_barrier_sync_invoke_and_complete + 132
    20  CoreData                            0x00007fff25109d6f _perform + 196
    21  CoreData                            0x00007fff25109b93 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 175
    22  CoreData                            0x00007fff250d49c2 -[NSManagedObjectContext executeFetchRequest:error:] + 885
    23  CoreData                            0x00007fff251a9d7f -[NSManagedObjectContext _parentObjectsForFetchRequest:inContext:error:] + 477
    24  CoreData                            0x00007fff251aa774 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 603
    25  CoreData                            0x00007fff25109de8 internalBlockToNSManagedObjectContextPerform + 89
    26  libdispatch.dylib                   0x000000010a6b0a88 _dispatch_client_callout + 8
    27  libdispatch.dylib                   0x000000010a6bfe11 _dispatch_async_and_wait_invoke + 175
    28  libdispatch.dylib                   0x000000010a6b0a88 _dispatch_client_callout + 8
    29  libdispatch.dylib                   0x000000010a6bef23 _dispatch_main_queue_callback_4CF + 1152
    30  CoreFoundation                      0x00007fff203a8276 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    31  CoreFoundation                      0x00007fff203a2b06 __CFRunLoopRun + 2685
    32  CoreFoundation                      0x00007fff203a1b9e CFRunLoopRunSpecific + 567
    33  GraphicsServices                    0x00007fff2b773db3 GSEventRunModal + 139
    34  UIKitCore                           0x00007fff24660af3 -[UIApplication _run] + 912
    35  UIKitCore                           0x00007fff24665a04 UIApplicationMain + 101
    36  XXXX                                0x0000000106de2d69 main + 153
    37  libdyld.dylib                       0x00007fff20257415 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings 
.'

【讨论】:

【参考方案2】:

您可以将批量大小设置为 0 [NSManagedObject MR_setDefaultBatchSize:0];,但之后检查您的性能。

【讨论】:

这似乎为我解决了问题

以上是关于仅在 iOS 14 中崩溃核心数据的主要内容,如果未能解决你的问题,请参考以下文章

UIPrintInteractionController 仅在 iOS 14 上单击“取消”按钮时崩溃

使用带有 ios 5 核心数据并发的 RestKit 时崩溃

应用程序仅在 iPhone 8 iOS 14.4.1 上因内存不足而崩溃

应用程序在核心数据中崩溃,但无法找到崩溃的位置

崩溃前保存核心数据上下文

xcode ios:将核心数据包含到旧项目后崩溃