IceCubesApp/Packages/Env/Sources/Env/Ext/AppStorage.swift

22 lines
501 B
Swift
Raw Normal View History

import Foundation
extension Array: RawRepresentable where Element: Codable {
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode([Element].self, from: data)
else {
return nil
}
self = result
}
2023-01-17 10:36:01 +00:00
public var rawValue: String {
guard let data = try? JSONEncoder().encode(self),
let result = String(data: data, encoding: .utf8)
else {
return "[]"
}
return result
}
}