使用nspredicate获取“'不能在不可变模型中修改命名的获取请求”

时间:2019-01-18 17:22:59

标签: ios swift nspredicate

我正在将fetchRequestTemplate与NSPredicate一起使用以获取数据。我在以下代码段上看到“线程1:信号SIGABRT”:

fetchRequest.predicate = NSPredicate(format: "userID == %@", userID)

这是问题的完整说明:

    2019-01-18 16:36:54.084567+0300 Chat[62769:8009479] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't modify a named fetch request in an immutable model.'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000107e811bb __exceptionPreprocess + 331
        1   libobjc.A.dylib                     0x0000000106e73735 objc_exception_throw + 48
        2   CoreData                            0x00000001077c7217 -[NSFetchRequest(_NSInternalMethods) _throwIfNotEditable] + 71
        3   CoreData                            0x00000001077c725e -[NSFetchRequest setPredicate:] + 30
        4   Chat                                0x00000001064d2db7 $S4Chat7MessageC11getMessages3for2inSayACGSgSS_So22NSManagedObjectContextCtFZ
+ 871
        5   Chat                                0x00000001064d2430 $S4Chat14StorageManagerC12readMessages3forSayAA12MessageModelCGSS_tF + 336
        6   Chat                                0x00000001064abfa9 $S4Chat20CommunicationManagerCACycfc + 2553
        7   Chat                                0x00000001064a8130 $S4Chat20CommunicationManagerCACycfC + 64
        8   Chat                                0x00000001064a80dc globalinit_33_C5FFB30340A1F300E36AFF644D48A8DA_func0 + 28
        9   libdispatch.dylib                   0x000000010a30a602 _dispatch_client_callout + 8
        10  libdispatch.dylib                   0x000000010a30c0c4 _dispatch_once_callout + 66
        11  libswiftCore.dylib                  0x0000000108676ea9 swift_once + 25
        12  Chat                                0x00000001064a81b4 $S4Chat20CommunicationManagerC06sharedbC0ACvau + 36
        13  Chat                                0x00000001064d599f $S4Chat11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF
+ 159
        14  Chat                                0x00000001064d5ac4 $S4Chat11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtFTo
+ 228
        15  UIKitCore                           0x000000010bd02bde -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 280
        16  UIKitCore                           0x000000010bd045cb -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3979
        17  UIKitCore                           0x000000010bd09c2f -[UIApplication _runWithMainScene:transitionContext:completion:] + 1623
        18  UIKitCore                           0x000000010b5284e9 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke
+ 866
        19  UIKitCore                           0x000000010b53129c +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
        20  UIKitCore                           0x000000010b528126 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 233
        21  UIKitCore                           0x000000010b528ae0 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1085
        22  UIKitCore                           0x000000010b526cb5 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke
+ 795
        23  UIKitCore                           0x000000010b52695f -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 435
        24  UIKitCore                           0x000000010b52ba90 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke
+ 584
        25  UIKitCore                           0x000000010b52c80e _performActionsWithDelayForTransitionContext + 100
        26  UIKitCore                           0x000000010b52b7ef -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]
+ 221
        27  UIKitCore                           0x000000010b53093a -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
        28  UIKitCore                           0x000000010bd0844e -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
        29  UIKitCore                           0x000000010b8acd09 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 357
        30  FrontBoardServices                  0x00000001143e82da -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
        31  FrontBoardServices                  0x00000001143f3443 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 271
        32  FrontBoardServices                  0x00000001143f2b3a __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
        33  libdispatch.dylib                   0x000000010a30a602 _dispatch_client_callout + 8
        34  libdispatch.dylib                   0x000000010a30db78 _dispatch_block_invoke_direct + 301
        35  FrontBoardServices                  0x0000000114427ba8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
        36  FrontBoardServices                  0x0000000114427860 -[FBSSerialQueue _performNext] + 457
        37  FrontBoardServices                  0x0000000114427e40 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
        38  CoreFoundation                      0x0000000107de6721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        39  CoreFoundation                      0x0000000107de5f93 __CFRunLoopDoSources0 + 243
        40  CoreFoundation                      0x0000000107de063f __CFRunLoopRun + 1263
        41  CoreFoundation                      0x0000000107ddfe11 CFRunLoopRunSpecific + 625
        42  GraphicsServices                    0x00000001114271dd GSEventRunModal + 62
        43  UIKitCore                           0x000000010bd0b81d UIApplicationMain + 140
        44  Chat                                0x00000001064d7037 main + 71
        45  libdyld.dylib                       0x000000010a380575 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 

0 个答案:

没有答案