Created
January 31, 2017 15:29
-
-
Save amitpdev/351ef852674d909c0f6e09bca057ec82 to your computer and use it in GitHub Desktop.
A nice example for writing a "multi-dimensional" enum with Swift
This file contains 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
enum HomeStatus: Int { | |
case pending = 1 | |
case active = 2 | |
case inactive = 3 | |
case deleted = 4 | |
var title: String { | |
switch self { | |
case .pending: | |
return "my_listings_status_pending".localized() | |
case .active: | |
return "my_listings_status_active".localized() | |
case .inactive: | |
return "my_listings_status_inactive".localized() | |
case .deleted: | |
return "my_listings_status_deleted".localized() | |
} | |
} | |
var color: UIColor { | |
switch self { | |
case .pending: | |
return UIColor.orange | |
case .active: | |
return UIColor(hex: Constant.Color.ListingActiveGreen) | |
case .inactive: | |
return UIColor.gray | |
case .deleted: | |
return UIColor.red | |
} | |
} | |
var changeable: Bool { | |
switch self { | |
case .deleted: | |
return false | |
case .active, | |
.inactive, | |
.pending: | |
return true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment