早上好 :)
我想使用带有 nsmanagedobject 的粘贴板。这是我的课:
import Foundation
import CoreData
@objc(Persons)
public class Persons: NSManagedObject {
@NSManaged public var firstName: String?
@NSManaged public var secondName: String?
}
我的视图控制器:
var persons = [Persons]() // filled in another code part
override func viewDidLoad() {
pboard.declareTypes(["MyType"],owner: nil)
pboard.setData(NSKeyedArchiver.archivedData(withRootObject: persons), forType: "MyType")
}
应用程序因以下日志而崩溃:
2017-06-23 08:16:18.605141+0200 TableView-DragDrop[29133:3726505]
-[Persons encodeWithCoder:]: unrecognized selector sent to instance 0x600000088f20 2017-06-23 08:16:18.606057+0200 TableView-DragDrop[29133:3726505] [General] -[Persons encodeWithCoder:]: unrecognized selector sent to instance 0x600000088f20 2017-06-23 08:16:18.609989+0200 TableView-DragDrop[29133:3726505] [General] ( 0 CoreFoundation 0x00007fffb9eae57b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffcf0f21da objc_exception_throw + 48 2 CoreFoundation 0x00007fffb9f2ef14 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fffb9e21c93
___forwarding___ + 1059 4 CoreFoundation 0x00007fffb9e217e8 _CF_forwarding_prep_0 + 120 5 Foundation 0x00007fffbb8ae95a _encodeObject + 1241 6 Foundation 0x00007fffbb8aff0c -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 460 7 Foundation 0x00007fffbb8ae95a
_encodeObject + 1241 8 Foundation 0x00007fffbb8ea492 +[NSKeyedArchiver archivedDataWithRootObject:] + 156 9 TableView-DragDrop 0x0000000100003147
_TFC18TableView_DragDrop8SourceVC9tableViewfTCSo11NSTableView13writeRowsWithV10Foundation8IndexSet2toCSo12NSPasteboard_Sb
+ 583 10 TableView-DragDrop 0x00000001000033bc _TToFC18TableView_DragDrop8SourceVC9tableViewfTCSo11NSTableView13writeRowsWithV10Foundation8IndexSet2toCSo12NSPasteboard_Sb
+ 108 11 AppKit 0x00007fffb80d4109 -[NSTableView _sendDataSourceWriteDragDataWithIndexes:toPasteboard:] + 102 12 AppKit 0x00007fffb80d4d06
-[NSTableView _performClassicDragOfIndexes:hitRow:event:] + 180 13 AppKit 0x00007fffb7bf67b5 -[NSTableView
_performDragFromMouseDown:] + 468 14 AppKit 0x00007fffb7bf4adf -[NSTableView mouseDown:] + 735 15 AppKit 0x00007fffb821824f -[NSWindow(NSEventRouting)
_handleMouseDownEvent:isDelayedEvent:] + 6341 16 AppKit 0x00007fffb8214a6c -[NSWindow(NSEventRouting)
_reallySendEvent:isDelayedEvent:] + 1942 17 AppKit 0x00007fffb8213f0a -[NSWindow(NSEventRouting) sendEvent:] + 541 18 AppKit 0x00007fffb8098681
-[NSApplication(NSEvent) sendEvent:] + 1145 19 AppKit 0x00007fffb7913427 -[NSApplication run] + 1002 20 AppKit 0x00007fffb78dde0e NSApplicationMain + 1237 21 TableView-DragDrop 0x00000001000058ad main + 13 22 libdyld.dylib 0x00007fffcf9d3235 start + 1 23 ??? 0x0000000000000003 0x0 + 3 ) 2017-06-23 08:16:18.611031+0200 TableView-DragDrop[29133:3726505] *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had
-finishEncoding called on it.
谁能帮我?