iosswiftswift3.2

Binary operator cannot be applied to operands of type Int and String - Swift 2.3 -> Swift 3.2 conversion error


While converting from Swift 2.3 to 3.2 I received below error.

Error : Binary operator cannot be applied to operands of type Int and String

for this if Condition i.e if (error?.code)! == "-112" which is shown in below line.

if (error?.code)! == "-112" 
{
     print("hello")
}

Solution

  • Error itself says it's different types Int and String.

    You can need to typecast one or another in same form and them compare.

    if (String(error?.code)!) == "-112"){
      print("hello")
    }