General question regarding swift enum.
I want to create an enum of \"icon\" and \"associate\" a value to the enum case
enum Icon {
case plane
case ar
More cleaner and readable
enum Icon {
case plane
case arrow
case logo
case flag
var image: UIImage {
return value.image
}
var color: UIColor {
return value.color
}
private var value: (image: UIImage, color: UIColor) {
switch self {
case .plane: return (UIImage(named: "plane.png")!, UIColor.green)
case .arrow: return (UIImage(named: "arrow.png")!, UIColor.green)
case .logo: return (UIImage(named: "logo.png")!, UIColor.green)
case .flag: return (UIImage(named: "flag.png")!, UIColor.green)
}
}
}
// Use
Icon.plane.image
Icon.plane.color