0

Using Swift 3 and am having problems comparing an Int32 and Int in an IF statement.

// myIntFromCoreData is an Int32
// kMyConstant is an Int

if myIntFromCoreData == kMyConstant // error: Binary operator "==" cannot be applied to operands of type 'Int32' and 'Int'
{
     Log("Cool")
}

So, I tried casting the values to Int32 or Int using:

myint32.intValue // Value of type 'Int32' has no member 'intValue'

myint32 as Int // Cannot convert value of type 'Int32' to type 'Int' in coercion

kMyConstant as Int32 // Cannot convert value of type 'Int' to type 'Int32' in coercion

But kept getting the above errors. Can anybody provide some direction no how to handle this?

Vee
  • 1,821
  • 3
  • 36
  • 60

1 Answers1

13

You can try this.

let number1: Int32 = 10
let number2 = Int(number1)
Community
  • 1
  • 1
vishwarajanand
  • 1,021
  • 13
  • 23