@@ -12,7 +12,12 @@ struct BackupFileDocument: FileDocument {
1212 static var readableContentTypes : [ UTType ] { [ . json] }
1313 static var writableContentTypes : [ UTType ] { [ . json] }
1414 static func toBackupItem( item: Item ) -> BackupItem {
15- . init( title: item. title, details: item. details, timestamp: item. timestamp, colorTag: item. colorTag)
15+ . init(
16+ title: item. title,
17+ details: item. details,
18+ timestamp: item. timestamp,
19+ colorTag: item. colorTag
20+ )
1621 }
1722
1823 let items : [ BackupItem ]
@@ -42,7 +47,12 @@ extension BackupFileDocument {
4247 let colorTag : Color ?
4348
4449 var realItem : Item {
45- . init( title: title, details: details, timestamp: timestamp, colorTag: colorTag)
50+ . init(
51+ title: title,
52+ details: details,
53+ timestamp: timestamp,
54+ colorTag: colorTag
55+ )
4656 }
4757
4858 private enum CodingKeys : String , CodingKey {
@@ -61,11 +71,12 @@ extension BackupFileDocument {
6171 title = try container. decode ( String . self, forKey: . title)
6272 details = try container. decode ( String . self, forKey: . details)
6373 timestamp = try container. decode ( Date . self, forKey: . timestamp)
64-
65- // Для обратной совместимости с старыми резервными копиями
66- if container. contains ( . colorTag) {
67- let colorData = try container. decode ( Data . self, forKey: . colorTag)
68- colorTag = try NSKeyedUnarchiver . unarchivedObject ( ofClass: UIColor . self, from: colorData) . map { Color ( uiColor: $0) }
74+ // Для обратной совместимости со старыми резервными копиями
75+ if let colorData = try container. decodeIfPresent ( Data . self, forKey: . colorTag) {
76+ colorTag = try NSKeyedUnarchiver . unarchivedObject (
77+ ofClass: UIColor . self,
78+ from: colorData
79+ ) . map ( Color . init)
6980 } else {
7081 colorTag = nil
7182 }
@@ -76,10 +87,12 @@ extension BackupFileDocument {
7687 try container. encode ( title, forKey: . title)
7788 try container. encode ( details, forKey: . details)
7889 try container. encode ( timestamp, forKey: . timestamp)
79-
8090 if let colorTag {
8191 let uiColor = UIColor ( colorTag)
82- let colorData = try NSKeyedArchiver . archivedData ( withRootObject: uiColor, requiringSecureCoding: false )
92+ let colorData = try NSKeyedArchiver . archivedData (
93+ withRootObject: uiColor,
94+ requiringSecureCoding: false
95+ )
8396 try container. encode ( colorData, forKey: . colorTag)
8497 }
8598 }
0 commit comments