Skip to content

Commit

Permalink
fix serialization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lekom committed May 5, 2020
1 parent 5b63d26 commit cbf1215
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public struct UnsplashPhoto: Codable {
identifier = try container.decode(String.self, forKey: .identifier)
height = try container.decode(Int.self, forKey: .height)
width = try container.decode(Int.self, forKey: .width)
color = try container.decode(UIColor.self, forKey: .color)

if let hexString = try? container.decode(String.self, forKey: .color) {
color = UIColor(hexString: hexString)
} else {
color = nil
}

exif = try? container.decode(UnsplashPhotoExif.self, forKey: .exif)
user = try container.decode(UnsplashUser.self, forKey: .user)
urls = try container.decode([URLKind: URL].self, forKey: .urls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public struct UnsplashUser: Codable {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(identifier, forKey: .identifier)
try container.encode(username, forKey: .username)
try container.encode(firstName, forKey: .firstName)
try container.encode(lastName, forKey: .lastName)
try container.encode(name, forKey: .name)
try? container.encode(firstName, forKey: .firstName)
try? container.encode(lastName, forKey: .lastName)
try? container.encode(name, forKey: .name)
try container.encode(profileImage.convert({ ($0.key.rawValue, $0.value.absoluteString) }), forKey: .profileImage)
try container.encode(bio, forKey: .bio)
try container.encode(links, forKey: .links)
try container.encode(location, forKey: .location)
try container.encode(portfolioURL, forKey: .portfolioURL)
try? container.encode(bio, forKey: .bio)
try container.encode(links.convert({ ($0.key.rawValue, $0.value.absoluteString) }), forKey: .links)
try? container.encode(location, forKey: .location)
try? container.encode(portfolioURL, forKey: .portfolioURL)
try container.encode(totalCollections, forKey: .totalCollections)
try container.encode(totalLikes, forKey: .totalLikes)
try container.encode(totalPhotos, forKey: .totalPhotos)
Expand Down

0 comments on commit cbf1215

Please sign in to comment.