Skip to content

Instantly share code, notes, and snippets.

@xmeta
Created August 10, 2020 15:16
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 xmeta/ad3768e2330637d1f0f07985417aaf4f to your computer and use it in GitHub Desktop.
Save xmeta/ad3768e2330637d1f0f07985417aaf4f to your computer and use it in GitHub Desktop.
enum Color {
case Red, Green, Blue, Rgb(r: Int, g: Int, b: Int)
}
func to_hex(color: Color) -> String {
switch color {
case .Red:
return "#FF0000"
case .Green:
return "#00FF00"
case .Blue:
return "#0000FF"
case let .Rgb(r, g, b):
return String(format:"#%02X%02X%02X", r, g, b)
}
}
var color = Color.Rgb(
r: 255,
g: 255,
b: 255
)
print(to_hex(color: color))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment