Skip to content

Instantly share code, notes, and snippets.

@Alexs2424
Created May 20, 2019 02:20
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 Alexs2424/d583552f8664c0d82d6932fe1df918e0 to your computer and use it in GitHub Desktop.
Save Alexs2424/d583552f8664c0d82d6932fe1df918e0 to your computer and use it in GitHub Desktop.
Swift Version of the Lights Code to get it to work.
if let hexBackgroundColor = colorsToUse.background.toHex() {
print("BACKGROUND: \(hexBackgroundColor)")
let backgroundRed = self.getRed(forColor: colorsToUse.background)
let backgroundGreen = self.getGreen(forColor: colorsToUse.background)
let backgroundBlue = self.getBlue(forColor: colorsToUse.background)
print("RED: \(backgroundRed)")
if let red = backgroundRed, let blue = backgroundBlue, let green = backgroundGreen {
let redBackgroundStr = self.stringForRGBValue(value: red)
print("RED STR: \(redBackgroundStr)")
let greenBackgroundStr = self.stringForRGBValue(value: green)
let blueBackgroundStr = self.stringForRGBValue(value: blue)
let url = URL(string: "feeds/albumColor/data")
let parameters = ["value": "\(redBackgroundStr)-\(greenBackgroundStr)-\(blueBackgroundStr)"]
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else { return }
request.httpBody = httpBody
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if let response = response {
print(response)
}
if let data = data {
do {
let json = try JSONSerialization.jsonObject(with: data, options: [])
print(json)
} catch {
print(error)
}
}
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment