0

Is there a way to convert Data directly into Int64?

My solution is to convert Data -> String and then 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)
apinho
  • 2,235
  • 3
  • 25
  • 39

1 Answers1

0

have you tried with

let int64Value = data.withUnsafeBytes {
    $0.load(as: Int64.self)
}
Alastar
  • 1,284
  • 1
  • 8
  • 14