Skip to main content
 首页 » 操作系统

macos之无法创建对象之简单的核心数据应用程序

2024年01月01日40emanlee

我刚刚尝试创建一个简单的核心数据应用程序,但出现错误。我正在使用 Xcode 6.1 和 swift。我之前已经 swift 完成了这项工作并且没有任何问题所以我对我错过或忘记的事情感到困惑。我在 GitHub 上有这个项目 here

错误代码在底部。在查看 Apple 文档时 here , Apple 声明:

Cause: In your managed object model, you may have specified a custom class for the entity, but you have not implemented the class.

Remedy: Implement the custom class, or specify that the entity is represented by NSManagedObject.

我已将模型中的子类添加到项目中。

有人遇到这个问题并能指出正确的方向吗?

2014-12-21 14:20:25.983 CoreDataNoStoryBoard[72437:7539866] Failed to create new object 
2014-12-21 14:20:25.984 CoreDataNoStoryBoard[72437:7539866] ( 
0   CoreFoundation                      0x00007fff9270c64c __exceptionPreprocess + 172 
1   libobjc.A.dylib                     0x00007fff8bb356de objc_exception_throw + 43 
2   CoreFoundation                      0x00007fff9270c42a +[NSException raise:format:arguments:] + 106 
3   AppKit                              0x00007fff98329507 _NSSendCommitEditingSelector + 267 
4   AppKit                              0x00007fff97fcd2bf -[NSController _controllerEditor:didCommit:contextInfo:] + 185 
5   CoreFoundation                      0x00007fff925e533c __invoking___ + 140 
6   CoreFoundation                      0x00007fff925e5192 -[NSInvocation invoke] + 290 
7   CoreFoundation                      0x00007fff92683e56 -[NSInvocation invokeWithTarget:] + 54 
8   Foundation                          0x00007fff9399eabb __NSFireDelayedPerform + 364 
9   CoreFoundation                      0x00007fff9265fb44 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 
10  CoreFoundation                      0x00007fff9265f7d3 __CFRunLoopDoTimer + 1059 
11  CoreFoundation                      0x00007fff926d2d9d __CFRunLoopDoTimers + 301 
12  CoreFoundation                      0x00007fff9261c268 __CFRunLoopRun + 2024 
13  CoreFoundation                      0x00007fff9261b838 CFRunLoopRunSpecific + 296 
14  HIToolbox                           0x00007fff8cc3643f RunCurrentEventLoopInMode + 235 
15  HIToolbox                           0x00007fff8cc360be ReceiveNextEventCommon + 179 
16  HIToolbox                           0x00007fff8cc35ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71 
17  AppKit                              0x00007fff97bd86d1 _DPSNextEvent + 964 
18  AppKit                              0x00007fff97bd7e80 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194 
19  AppKit                              0x00007fff97bcbe23 -[NSApplication run] + 594 
20  AppKit                              0x00007fff97bb72d4 NSApplicationMain + 1832 
21  CoreDataNoStoryBoard                0x00000001000059b2 top_level_code + 34 
22  CoreDataNoStoryBoard                0x00000001000059ea main + 42 
23  libdyld.dylib                       0x00007fff97a805c9 start + 1 
24  ???                                 0x0000000000000003 0x0 + 3 
) 

请您参考如下方法:

根据NSManagedObject Subclass Documentation “Swift 类是有命名空间的——它们的作用域是它们在其中编译的模块(通常是项目)。要将 NSManagedObject 类的 Swift 子类与您的 Core Data 模型一起使用,请在模型的 Class 字段中为类名添加前缀带有模块名称的实体检查器。”

将您的应用名称添加到实体的类中,如下所示: