Rework the preference to avoid stringly typed properties.

This commit is contained in:
Damiano Galassi committed 2020-02-07 15:31:10 +01:00
1 parent 2694bdee45
commit fbc464e643
22 files changed
+321 -228

No files matched your search

@@ -89,22 +89,3 @@ public class MetadataResultMap: Codable {
self.type = type
}
}
extension UserDefaults {
func map(forKey defaultName: String) -> MetadataResultMap? {
let decoder = JSONDecoder()
guard let jsonData = self.data(forKey: defaultName),
let decoded = try? decoder.decode(MetadataResultMap.self, from: jsonData) else { return nil }
return decoded
}
func set(_ map: MetadataResultMap, forKey defaultName: String) {
let encoder = JSONEncoder()
let jsonData = try? encoder.encode(map)
self.set(jsonData, forKey: defaultName)
}
}