Skip to content

Instantly share code, notes, and snippets.

@chamook
Created February 28, 2019 11:14
Show Gist options
  • Save chamook/4e4e3a5400e8aea9c51239a625bead2c to your computer and use it in GitHub Desktop.
Save chamook/4e4e3a5400e8aea9c51239a625bead2c to your computer and use it in GitHub Desktop.
struct RGB: Decodable {
var red: Int
var green: Int
var blue: Int
enum CodingKeys: String, CodingKey {
case red = "Red"
case green = "Green"
case blue = "Blue"
}
}
struct Colour: Decodable {
var id: String
var name: String
var hex: String
var rgb: RGB
enum CodingKeys: String, CodingKey {
case id = "Id"
case name = "Name"
case hex = "Hex"
case rgb = "RGB"
}
}
private func loadColours() {
let url = URL(string: "http://localhost:5000/my-colours")!
var request = URLRequest(url: url)
request.setValue("application/vnd.chamook.api+json; including=id,name,hex,rgb", forHTTPHeaderField: "Accept")
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment