Ошибка coredata - supportsSecureCoding

coredata
swift

#1

Здравствуйте, подскажите пожалуйста, в чем я не прав?

Failure to save context: Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSUnderlyingError=0x600003555dd0 {Error Domain=NSCocoaErrorDomain Code=4866 "Данные не удалось записать, так как они имеют неверный формат." UserInfo={NSUnderlyingError=0x600003557090 {Error Domain=NSCocoaErrorDomain Code=4864 "Class 'InStat.Preferences' disallows secure coding. It must return YES from supportsSecureCoding." UserInfo={NSDebugDescription=Class 'InStat.Preferences' disallows secure coding. It must return YES from supportsSecureCoding.}}}}}

я пробовал в класс добавлять public static var supportsSecureCoding = true
Использовал как NSSecureUnarchiveFromDataTransformer так и NSSecureUnarchiveFromData

public class Preferences: NSObject, NSCoding {
    var id = 0
    var name = LanguageItem<String>(values: [:], defaultLanguage: "")
    var subName = LanguageItem<String>(values: [:], defaultLanguage: "")
    var flag = URL(string: "")
    var iconSport = ""
    var kindOfSport = 0
    var isSelected = false


init(id: Int, name: LanguageItem<String>, subName: LanguageItem<String>, flag: URL, iconSport: String, kindOfSport: Int, isSelected: Bool) {
    self.id = id
    self.name = name
    self.subName = subName
    self.iconSport = iconSport
    self.flag = flag
    self.kindOfSport = kindOfSport
    self.isSelected = isSelected
}

enum CodingKeys: String, CodingKey {
    case id, name, subName, iconSport, flag, kindOfSport, isSelected
}

public override init() {
    super.init()
}
public func encode(with aCoder: NSCoder) {
    aCoder.encode(id, forKey: CodingKeys.id.rawValue)
    aCoder.encode(name, forKey: CodingKeys.name.rawValue)
    aCoder.encode(subName, forKey: CodingKeys.subName.rawValue)
    aCoder.encode(iconSport, forKey: CodingKeys.iconSport.rawValue)
    aCoder.encode(flag, forKey: CodingKeys.flag.rawValue)
    aCoder.encode(kindOfSport, forKey: CodingKeys.kindOfSport.rawValue)
    aCoder.encode(isSelected, forKey: CodingKeys.isSelected.rawValue)
}


public required convenience init?(coder aDecoder: NSCoder) {
    let id = aDecoder.decodeObject(forKey: CodingKeys.id.rawValue) as? Int ?? 0
    let name = aDecoder.decodeObject(forKey: CodingKeys.name.rawValue) as? LanguageItem<String> ?? LanguageItem<String>(values: [:], defaultLanguage: "")
    let subName = aDecoder.decodeObject(forKey: CodingKeys.subName.rawValue) as? LanguageItem<String> ?? LanguageItem<String>(values: [:], defaultLanguage: "")
    let iconSport = aDecoder.decodeObject(forKey: CodingKeys.iconSport.rawValue)  as? String ?? ""
    let flag = aDecoder.decodeObject(forKey: CodingKeys.flag.rawValue) as? URL ?? URL(string: "")
    let kindOfSport = aDecoder.decodeObject(forKey: CodingKeys.kindOfSport.rawValue) as? Int ?? 0
    let isSelected = aDecoder.decodeObject(forKey: CodingKeys.isSelected.rawValue) as? Bool ?? false
    self.init(id: id, name: name, subName: subName, flag: (flag ?? URL(string: ""))!, iconSport: iconSport, kindOfSport: kindOfSport, isSelected: isSelected)
}

}