Skip to content

Instantly share code, notes, and snippets.

@nickoneill
Created July 17, 2016 17:53
Show Gist options
  • Save nickoneill/8ff8a5fccdc154c3fb3d5f2022fec7b0 to your computer and use it in GitHub Desktop.
Save nickoneill/8ff8a5fccdc154c3fb3d5f2022fec7b0 to your computer and use it in GitHub Desktop.
Too many enums?
/**
`ZebraPrinterStatus` is a list of status responses we handle from the printer or during a connection attempt with the printer.
*/
enum ZebraPrinterStatus {
case Ready
case NotReady([ZebraPrinterError])
case Unknown
func message() -> String {
switch self {
case .Ready:
return "Printer Ready"
case let .NotReady(errors):
var errorMessages = ""
for error in errors {
errorMessages += error.rawValue + ","
}
return "Printer not ready: \(errorMessages)"
case .Unknown:
return "Unknown status"
}
}
}
/**
`ZebraPrinterError` enumerates the error types that we can receive when communicating with the printer. Other than the timeout case, all other responses are reported by the printer itself.
*/
enum ZebraPrinterError: String {
case ThermOpen = "Thermistor Open"
case InvalidConfig = "Invalid firmware configuration"
case NoPrinthead = "Printhead detection error"
case BadPrinthead = "Bad printhead element"
case MotorTemp = "Motor over temperature"
case PrintheadTemp = "Printhead over temperature"
case CutterFault = "Cutter fault"
case HeadOpen = "Head open"
case RibbonOut = "Out of ribbon"
case MediaOut = "Out of labels"
case Timeout = "Couldn't connect to printer"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment