Skip to content

Instantly share code, notes, and snippets.

@AndrewSB
Forked from danstepanov/paid status
Last active January 19, 2016 01:43
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 AndrewSB/05517bf4a9ac25c8a7d4 to your computer and use it in GitHub Desktop.
Save AndrewSB/05517bf4a9ac25c8a7d4 to your computer and use it in GitHub Desktop.
// Assuming you have a class called API for all your API stuff
extension API {
enum PaidStatus: String {
case Paid
case Scheduled
}
}
if let paidStatus = API.PaidStatus(rawValue: paystubData.status.capitilzedString) {
switch paidStatus {
case .Paid:
cell.paidStatusLabel.text = API.PaidStatus.Paid.rawValue.uppercaseString
case .Scheduled:
cell.paidStatusLabel.text = API.PaidStatus.Paid.rawValue.uppercaseString
}
// (or I'd just recommend not switching and just doing this)
cell.paidStatusLabel.text = paidStatus.rawValue.uppercaseString
} else {
cell.paidStatusLabel.text = ""
}
// Or a beautiful one liner would be
cell.paidStatusLabel.text = API.PaidStatus(rawValue: paystubData.status.capitilzedString)?.rawValue.uppercaseString ?? ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment