mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-04-28 18:58:47 +00:00
22 lines
501 B
Swift
22 lines
501 B
Swift
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
|
|
}
|
|
|
|
public var rawValue: String {
|
|
guard let data = try? JSONEncoder().encode(self),
|
|
let result = String(data: data, encoding: .utf8)
|
|
else {
|
|
return "[]"
|
|
}
|
|
return result
|
|
}
|
|
}
|