Как кодировать / декодировать переменную NSOrderedSet в swift4, кодируемую при отображении coredata NSManagedObject?
import CoreData
import Foundation
@objc(TestObject)
public class TestObject:NSManagedObject,Encodable
{
@nonobjc public class func fetchRequest() -> NSFetchRequest<TestObject> {
return NSFetchRequest<TestObject>(entityName: "TestObject")
}
@NSManaged public var testName: String?
@NSManaged public var devices: NSOrderedSet? // of entity type "Device"
enum CodingKeys: String, CodingKey {
case testName
case devices
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy:CodingKeys.self)
try container.encode(testName,forKey:.testName)
try container.encode(devices,forKey:.devices)
}
}
public required convenience init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
try container.decode(testName,forKey:.testName)
try container.decode(devices,forKey:.devices)
}
Выдает ошибку: Компилятор выдает эту ошибку
No 'decode' candidates produce the expected contextual result type 'NSOrderedSet?'