Binary operator '~ =' cannot be applied to two operands of UmRet

I am working on integrating swiper IDTech into my application and I have gone pretty far, added a library, logged notifications, unregistered them, and now I am working on a function that connects the reader. I cannot figure out what I am doing wrong here when I try to switch cases based on the return value. Can someone please help me?

func displayUmRet(operation: String, returnValue: UmRet) {

        var string = ""

    do {
        switch returnValue {

        case UMRET_SUCCESS: string = ""
        case UMRET_NO_READER: string="No reader attached"
        case UMRET_SDK_BUSY: string="Communication with reader in progress"
        case UMRET_MONO_AUDIO: string="Mono audio enabled"
            case UMRET_ALREADY_CONNECTED: string="Already connected"
            case UMRET_LOW_VOLUME: string="Low volume"
            case UMRET_NOT_CONNECTED: string="Not connected"
            case UMRET_NOT_APPLICABLE: string="Not applicable to reader type"
            case UMRET_INVALID_ARG: string="Invalid argument"
            case UMRET_UF_INVALID_STR: string="Invalid firmware update string"
            case UMRET_UF_NO_FILE: string="Firmware file not found"
            case UMRET_UF_INVALID_FILE: string="Invalid firmware file"
            default: string="<unknown code>"
        }
    } while (0)

   // var retStatus = UMRET_SUCCESS==ret

    //self.textResponse.text = "\(operation), \(retStatus), \(string)"

    self.hexResponse.text = "";


}

      

+3


source to share


1 answer


You need to put .

in front of your affairs:

enum UmRet {
  case UMRET_SUCCESS, UMRET_FAILURE
}

var string = " "

let returnValue = UmRet.UMRET_SUCCESS

switch returnValue {
case .UMRET_SUCCESS: string = "y"
case .UMRET_FAILURE: string = "n"
}

      

Also, 0

not the same as false

in Swift, so:

do {
...
} while (0)

      

Does not work.

And you don't need semicolons at the end of the line, so this:



self.hexResponse.text = "";

      

could be as follows:

self.hexResponse.text = ""

      

And finally, if your switch statement has every case for every case in your enum, you don't need a default case. (that's why mine didn't have one in the example)

By the way, ~=

this is just a statement for the pattern matching function, which is what Swift does in a switch statement. It works like a function ==

, for example is the Int ~= Int

same as Int == Int

. But it is a little more versatile: for example, Range ~= Int

for example, it 0...3 ~= 2

returns whether or not it is Int

in a range. (So ​​true in this case) For enums, this is the case. In my example, it will match UMRET_SUCCESS

and string

will be set to y

.

+3


source







All Articles