我使用 swift 3和nsoutlineview. 我想将核心数据记录的objectID保存到文本字段中. 所以我必须将其转换为字符串: txtFied.stringValue = "\(CoreData[outlineView.selectedRow].objectID)" 我怎样才能将它转换回
我想将核心数据记录的objectID保存到文本字段中.
所以我必须将其转换为字符串:
txtFied.stringValue = "\(CoreData[outlineView.selectedRow].objectID)"
我怎样才能将它转换回NSManagedObjectID?
我通过持久性存储协调器的managedObjectID(forURIRepresentation :)方法完成了这个,如下所述:// Convert NSManagedObjectID to a string, via the uriRepresentation method. let objectIDString = <your managed object ID>.uriRepresentation().absoluteString ... // Use the persistent store coordinator to transform the string back to an NSManagedObjectID. if let objectIDURL = URL(string: objectIDString) { let coordinator: NSPersistentStoreCoordinator = <reference to your persistent store coordinator> let managedObjectID = coordinator.managedObjectID(forURIRepresentation: objectIDURL) }