swift - 无法将类型 'Int64?' 的值转换为预期的参数类型 'Int'

标签 swift casting int int64

当我尝试将 job?.id(一个 Int64)作为 Int 参数传递时(虽然我知道它没有那么大),swift 编译器提示这个错误,我尝试了几种方法来转换它,但没有成功:

Cannot convert value of type 'Int64?' to expected argument type 'Int'

我的代码:

Job.updateJobStatus(token: tok, jobId: job?.id, status:JobSatus.canceled) { (result, error) in
        if result != nil
        {

        }
        else if error != nil
        {

        }
    }

最佳答案

你可以很容易地去:

let int64Value: Int64 = 123456
let intValue = NSNumber(value: int64Value).intValue

关于swift - 无法将类型 'Int64?' 的值转换为预期的参数类型 'Int',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47514183/

相关文章:

string - java - 如何在java中将String []解析为int []?

ios - 如何根据父 View 的位置和大小更新 UIView 的位置和大小? [ swift ]

ObservedObject 更改时 SwiftUI View 未更新

swift - 如何在 swift 4 中对数组中的 JSON 数据进行排序

c++ - 将枚举类型转换为整数,反之亦然

c++ - static int 执行了多少次?

ios - 带有 CollectionView 和文本行的 TableView 部分

c# - 如何将 Object 转换为其实际类型?

PostgreSQL-错误 : column "date" cannot be cast to type date

c - scanf 和 printf 中的无效 int