Created
August 4, 2020 20:58
-
-
Save 0xLeif/9b307dc392b6c48403004fb4907f3d65 to your computer and use it in GitHub Desktop.
ColorDump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
var bag = [AnyCancellable]() | |
struct Color { | |
let name: String | |
let hex: String | |
} | |
extension Color: CustomStringConvertible { | |
var description: String { | |
"\(name): \(hex)" | |
} | |
} | |
let valuesToReplace = "%'-" | |
URLSession.shared.dataTaskPublisher(for: URL(string: "https://raw.githubusercontent.com/meodai/color-names/master/src/colornames.csv")!) | |
.sink(receiveCompletion: { (event) in | |
print(event) | |
}) { (data: Data, response: URLResponse) in | |
guard let csv = String(data: data, encoding: .utf8) else { | |
print("Failed to unwrap CSV Data") | |
return | |
} | |
let colorData = csv.split(separator: "\r\n").dropFirst().map { $0.split(separator: ",") } | |
let colors = colorData.map { | |
Color(name: $0[0].description, hex: $0[1].description) | |
} | |
colors.forEach { | |
print("case \($0.name) = \"\($0.hex)\"") | |
} | |
} | |
.store(in: &bag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment