Swift + 核心数据:在 swift 中生成其子类后无法添加托管对象

Swift + Core Data : Unable to add managed object after generating its subclass in swift

我创建了一个数据模型,如下所示:

将 ArrayController 实体名称更新为:DownloadingFile,并执行相关绑定:

一个。 ArrayController 绑定

b. Table-列绑定

c.添加按钮绑定

我点击了 'Add' 按钮,它按预期完美运行:)

然后我在 swift 中生成了我的托管对象的子 class,突然它开始崩溃,控制台中打印了以下堆栈跟踪:

2015-06-21 00:38:13.073 TableViewBindingsSample[2390:48630] Failed to create new object
2015-06-21 00:38:13.075 TableViewBindingsSample[2390:48630] (
    0   CoreFoundation                      0x00007fff838b703c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8687d76e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff838b6e1a +[NSException raise:format:arguments:] + 106
    3   AppKit                              0x00007fff84fd34c9 _NSSendCommitEditingSelector + 267
    4   AppKit                              0x00007fff84fd35ab -[NSController _controllerEditor:didCommit:contextInfo:] + 185
    5   CoreFoundation                      0x00007fff8378e7bc __invoking___ + 140
    6   CoreFoundation                      0x00007fff8378e612 -[NSInvocation invoke] + 290
    7   CoreFoundation                      0x00007fff8382e5c6 -[NSInvocation invokeWithTarget:] + 54
    8   Foundation                          0x00007fff8812b41b __NSFireDelayedPerform + 364
    9   CoreFoundation                      0x00007fff8380a2e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    10  CoreFoundation                      0x00007fff83809f73 __CFRunLoopDoTimer + 1059
    11  CoreFoundation                      0x00007fff8387d53d __CFRunLoopDoTimers + 301
    12  CoreFoundation                      0x00007fff837c5608 __CFRunLoopRun + 2024
    13  CoreFoundation                      0x00007fff837c4bd8 CFRunLoopRunSpecific + 296
    14  HIToolbox                           0x00007fff8c3cf56f RunCurrentEventLoopInMode + 235
    15  HIToolbox                           0x00007fff8c3cf1ee ReceiveNextEventCommon + 179
    16  HIToolbox                           0x00007fff8c3cf12b _BlockUntilNextEventMatchingListInModeWithFilter + 71
    17  AppKit                              0x00007fff84c429bb _DPSNextEvent + 978
    18  AppKit                              0x00007fff84c41f68 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
    19  AppKit                              0x00007fff84c37bf3 -[NSApplication run] + 594
    20  AppKit                              0x00007fff84bb4354 NSApplicationMain + 1832
    21  TableViewBindingsSample             0x0000000100003c87 main + 87
    22  libdyld.dylib                       0x00007fff865225c9 start + 1
    23  ???                                 0x0000000000000003 0x0 + 3
)

所以我尝试 google 解决并找到了开发人员提出的解决方案:Failed to Create Object - Simple Core Data App 但在我的情况下,建议的解决方案不起作用,事实上我无法添加项目名称作为 class 名称的前缀,用点分隔,当我尝试这样做时 Xcode 会自动删除添加的点 :(

有什么想法吗?

我通过从生成的 NSManagedObject 子类中删除 @objc(EntityName) 来让它工作。