Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created February 6, 2020 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/8e6ebc19e312b80cad808ea8943e4faf to your computer and use it in GitHub Desktop.
Save BetterProgramming/8e6ebc19e312b80cad808ea8943e4faf to your computer and use it in GitHub Desktop.
struct HeaderInformation: Decodable {
let title: String
let imageUrl: String
let textColor: UIColor
static var textColorUserInfoKey: CodingUserInfoKey {
return CodingUserInfoKey(rawValue: "textColor")!
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
title = try container.decode(String.self, forKey: .title)
imageUrl = try container.decode(String.self, forKey: .imageUrl)
textColor = decoder.userInfo[Self.textColorUserInfoKey] as? UIColor ?? .black
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment