【发布时间】:2015-12-07 23:49:50
【问题描述】:
我正在为我的应用程序使用 CoreData,但它无法运行。我有一个名为“Task”的实体,该实体有一个名为 Task.swift 的类
这是我收到的错误消息;
2015-12-07 17:13:24.669 ToDoList[8002:64192] CoreData: warning: Unable to load class named 'Task' for entity 'Task'. Class not found, using default NSManagedObject instead.
2015-12-07 17:13:24.677 ToDoList[8002:64192] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:6245
2015-12-07 17:13:24.679 ToDoList[8002:64192] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier reuseIdentifier - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f7ebc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111356bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010f7ebaca +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010fc8898f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x000000011017e264 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 153
5 ToDoList 0x000000010f1efd83 _TFC8ToDoList27TaskListTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 147
6 ToDoList 0x000000010f1f029f _TToFC8ToDoList27TaskListTableViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
7 UIKit 0x000000011018b9e8 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
8 UIKit 0x000000011016a208 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2853
9 UIKit 0x0000000110180869 -[UITableView layoutSubviews] + 210
10 UIKit 0x000000011010a9eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
11 QuartzCore 0x0000000113ed8ed2 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x0000000113ecd6e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000113ecd556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000113e3986e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000113e3aa22 _ZN2CA11Transaction6commitEv + 462
16 UIKit 0x00000001100889ed -[UIApplication _reportMainSceneUpdateFinished:] + 44
17 UIKit 0x00000001100896b1 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2648
18 UIKit 0x0000000110088095 -[UIApplication workspaceDidEndTransaction:] + 179
19 FrontBoardServices 0x0000000112e535e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
20 CoreFoundation 0x000000010f71f41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
21 CoreFoundation 0x000000010f715165 __CFRunLoopDoBlocks + 341
22 CoreFoundation 0x000000010f714f25 __CFRunLoopRun + 2389
23 CoreFoundation 0x000000010f714366 CFRunLoopRunSpecific + 470
24 UIKit 0x0000000110087b02 -[UIApplication _run] + 413
25 UIKit 0x000000011008a8c0 UIApplicationMain + 1282
26 ToDoList 0x000000010f1ecb47 main + 135
27 libdyld.dylib 0x0000000111a8c145 start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
类:
import Foundation
import CoreData
class Task: NSManagedObject {
@NSManaged var tDesc: String
@NSManaged var tImage: NSData
@NSManaged var tName: String
}
我已经查看了有关此主题的其他问题,但它们并没有太大帮助。我不知道还能做什么。有人可以帮忙吗!
谢谢
【问题讨论】:
-
看起来应该可以了。尝试执行 Project->Clean 并删除 ~/Library/Developer/Xcode/DerivedData/ToDoList-etc... 文件夹。然后重建你的项目。 — 有时这会解决一些神秘的问题。
-
我在哪里可以找到这个文件夹
-
使用 Finder,按 Command-Shift-G 并输入:
~/Library/Developer/Xcode/DerivedData— 您将看到每个项目的文件夹。删除以您的项目名称开头的那个。 -
在暂停执行后在调试提示符中输入
po NSClassFromString(@"Task")会得到什么? -
你有(至少)两个完全不相关的问题:#1:“CoreData:警告:无法加载名为'Task'的类”:看看stackoverflow.com/questions/25076276/…。您是否将实体的模块设置为“当前产品模块”? - #2 "*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]": 这可能是由于原型单元格中缺少重用标识符造成的。
标签: ios swift uitableview core-data appdelegate