ios - 将数据转换为 Int64

标签 ios swift xcode

有没有办法将Data直接转换为Int64

我的解决方案是转换 Data -> String 然后 String -> 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)

最佳答案

你尝试过

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

关于ios - 将数据转换为 Int64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56557251/

相关文章:

ios - 如何在 iOS 中将图像转换为视频时为图像制作动画?

ios - Swift 3 过滤 Json 和重新排序

ios - iOS 中的条码扫描器

ios - 旋转时,文本在 UITextView 行尾之前断到下一行

json - 使用 SwiftyJSON 和 Alamofire 在 TableView 上显示 JSON 数据

ios - 在 Swift 中优化从 Firestore 获取

ios - AFHTTPRequestOperation 超时

xcode - macOS应用程序帮助文档文件夹消失

objective-c - 错误 : Expected ; at end of declaration list - Class not recognized as type

xcode - 如何在 Xcode 中获取智能选项卡 ("indent with tabs, align with spaces") 行为?