将数据转换为Int64

时间:2019-06-12 07:58:17

标签: ios swift xcode

是否可以将Data直接转换为Int64

我的解决方案是先转换数据->字符串,然后转换成字符串-> Int64

let data = "123456".data(using: .utf8)! // data from string for example purposes


let idString = String(data: data, encoding: .utf8)! //IUO for example purposes too
let id = Int64(idString)

1 个答案:

答案 0 :(得分:0)

您尝试过

let int64Value = data.withUnsafeBytes {
    $0.load(as: Int64.self)
}