简体   繁体   English

将数据转换为Int64

[英]Convert Data to Int64

Is there a way to convert Data directly into Int64 ? 有没有办法将Data直接转换为Int64

My solution is to convert Data -> String and then String -> 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)

have you tried with 你试过吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM