File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ public struct ImageWrapper : Codable {
4+ public let image : Image
5+
6+ public enum CodingKeys : String , CodingKey {
7+ case image
8+ }
9+
10+ public init ( image: Image ) {
11+ self . image = image
12+ }
13+
14+ public init ( from decoder: Decoder ) throws {
15+ let container = try decoder. container ( keyedBy: CodingKeys . self)
16+ let data = try container. decode ( Data . self, forKey: CodingKeys . image)
17+ guard let image = Image ( data: data) else {
18+ throw StorageError . decodingFailed
19+ }
20+
21+ self . image = image
22+ }
23+
24+ public func encode( to encoder: Encoder ) throws {
25+ var container = encoder. container ( keyedBy: CodingKeys . self)
26+ guard let data = image. cache_toData ( ) else {
27+ throw StorageError . encodingFailed
28+ }
29+
30+ try container. encode ( data, forKey: CodingKeys . image)
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments