Swift 3 - 将Int32转换为Int

Vee*_*Vee 0 int conditional casting int32 swift3

使用Swift 3并且在IF语句中比较Int32和Int时遇到问题.

// 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")
}
Run Code Online (Sandbox Code Playgroud)

所以,我尝试使用以下方法将值转换为Int32或Int:

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
Run Code Online (Sandbox Code Playgroud)

但不断得到上述错误.任何人都可以提供一些方向,如何处理这个?

vis*_*and 8

你可以试试这个.

let number1: Int32 = 10
let number2 = Int(number1)
Run Code Online (Sandbox Code Playgroud)