【问题标题】:CoreData Error SIGABRT: keypath AttributeName not found in entity <NSSQLEntity EntityName id=2>CoreData 错误 SIGABRT: keypath AttributeName not found in entity <NSSQLEntity EntityName id=2>
【发布时间】:2016-05-07 09:11:13
【问题描述】:

我在我的 iOS 应用程序中使用核心数据。我有两个实体,“提交”,具有属性“commitID”、“completionStatus”、“contents”和“repeatStatus”,以及一个具有属性“dateID”的实体“ToDoList”。两者通过将许多 Commit 与一个 ToDoList 相关联的关系连接起来。

我每次都收到以下错误。我已经尝试删除并重新安装该应用程序,但无济于事。我知道这个错误是在我的 application(application: didFinishLaunchingWithOptions:) 方法之后抛出的:

2016-05-07 10:54:14.131 CommitToday[1836:47383] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath commitID not found in entity <NSSQLEntity ToDoList id=2>'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001027d7d85 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010457bdeb objc_exception_throw + 48
2   CoreData                            0x000000010242efff -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 1583
3   CoreData                            0x00000001023217e3 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 35
4   CoreData                            0x00000001024147b8 -[NSSQLAdapter _statementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 344
5   CoreData                            0x000000010232167c -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 316
6   CoreData                            0x00000001023212f6 -[NSSQLCore newRowsForFetchPlan:] + 118
7   CoreData                            0x0000000102320bac -[NSSQLCore objectsForFetchRequest:inContext:] + 524
8   CoreData                            0x0000000102320549 -[NSSQLCore executeRequest:withContext:error:] + 377
9   CoreData                            0x0000000102405eaf __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3311
10  CoreData                            0x000000010240f4dd gutsOfBlockToNSPersistentStoreCoordinatorPerform + 189
11  CoreData                            0x00000001024005ed _perform + 221
12  CoreData                            0x00000001023201b4 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 500
13  CoreData                            0x000000010231e973 -[NSManagedObjectContext executeFetchRequest:error:] + 579
14  CoreData                            0x000000010244d6c2 __43-[NSFetchedResultsController performFetch:]_block_invoke + 258
15  CoreData                            0x000000010240f4dd gutsOfBlockToNSPersistentStoreCoordinatorPerform + 189
16  libdispatch.dylib                   0x00000001050143eb _dispatch_client_callout + 8
17  libdispatch.dylib                   0x0000000104ff8ef5 _dispatch_barrier_sync_f_invoke + 393
18  CoreData                            0x00000001023ff076 -[NSPersistentStoreCoordinator performBlockAndWait:] + 198
19  CoreData                            0x0000000102366127 developerSubmittedBlockToNSManagedObjectContextPerform + 199
20  CoreData                            0x0000000102365fee -[NSManagedObjectContext performBlockAndWait:] + 222
21  CoreData                            0x000000010244d4bc -[NSFetchedResultsController performFetch:] + 524
22  CommitToday                         0x00000001022404e4 _TFC11CommitToday14ViewController11viewDidLoadfT_T_ + 164
23  CommitToday                         0x0000000102240d42 _TToFC11CommitToday14ViewController11viewDidLoadfT_T_ + 34
24  UIKit                               0x000000010319a984 -[UIViewController loadViewIfRequired] + 1198
25  UIKit                               0x00000001031defae -[UINavigationController _layoutViewController:] + 54
26  UIKit                               0x00000001031df882 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
27  UIKit                               0x00000001031df9f4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
28  UIKit                               0x00000001031e0c4d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
29  UIKit                               0x00000001031e1d0b -[UINavigationController __viewWillLayoutSubviews] + 57
30  UIKit                               0x0000000103390503 -[UILayoutContainerView layoutSubviews] + 248
31  UIKit                               0x00000001030ba980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
32  QuartzCore                          0x0000000107aafc00 -[CALayer layoutSublayers] + 146
33  QuartzCore                          0x0000000107aa408e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
34  QuartzCore                          0x0000000107aa3f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
35  QuartzCore                          0x0000000107a983c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
36  QuartzCore                          0x0000000107ac6086 _ZN2CA11Transaction6commitEv + 486
37  QuartzCore                          0x0000000107ac67f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
38  CoreFoundation                      0x00000001026fcc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
39  CoreFoundation                      0x00000001026fcba7 __CFRunLoopDoObservers + 391
40  CoreFoundation                      0x00000001026f211c CFRunLoopRunSpecific + 524
41  UIKit                               0x0000000102ffaf21 -[UIApplication _run] + 402
42  UIKit                               0x0000000102ffff09 UIApplicationMain + 171
43  CommitToday                         0x000000010223c302 main + 114
44  libdyld.dylib                       0x000000010504892d start + 1
45  ???                                 0x0000000000000001 0x0 + 1
)
  libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

【问题讨论】:

  • 您的核心数据模型是否有多个版本?
  • 如何知道我的核心数据模型有多少个版本?
  • 您将选择 *.xcdatamodel 文件,然后在右侧单击“显示文件检查器”,然后查看“模型版本”->“当前版本”部分并选择您的文件
  • 它正在 ToDoList 实体上寻找一个名为 commitID 的属性 - 这表明您的获取结果控制器配置不正确。显示代码。
  • 谢谢@pbasdf 我在 fetchRequest 中发现了错误。如果你发布你的答案,我可以接受它是正确的。

标签: ios swift sqlite core-data nsexception


【解决方案1】:

来自错误信息:

由于未捕获的异常“NSInvalidArgumentException”而终止应用,原因:“keypath commitID not found in entity [NSSQLEntity ToDoList id=2]”

它似乎试图访问ToDoList 实体上名为commitID 的属性。这表明您的 fetch 或 fetched results 控制器配置不正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2019-01-29
    相关资源
    最近更新 更多