Skip to content

Instantly share code, notes, and snippets.

@amitpdev
Created January 31, 2017 15:29
Show Gist options
  • Save amitpdev/351ef852674d909c0f6e09bca057ec82 to your computer and use it in GitHub Desktop.
Save amitpdev/351ef852674d909c0f6e09bca057ec82 to your computer and use it in GitHub Desktop.
A nice example for writing a "multi-dimensional" enum with Swift
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