【问题标题】:Swift 3 - convert Int32 to Int [duplicate]Swift 3 - 将 Int32 转换为 Int [重复]
【发布时间】:2017-03-02 04:30:29
【问题描述】:

使用 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")
}

所以,我尝试使用以下方法将值转换为 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

但不断收到上述错误。任何人都可以提供一些指导而不是如何处理这个吗?

【问题讨论】:

    标签: casting swift3 int conditional int32


    【解决方案1】:

    你可以试试this

    let number1: Int32 = 10
    let number2 = Int(number1)
    

    【讨论】:

    • 工作就像一个魅力。谢谢!
    猜你喜欢
    • 2015-08-20
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    • 2017-04-07
    • 2015-03-14
    • 1970-01-01
    相关资源
    最近更新 更多