Data+Extension.swift 469 B

1234567891011121314151617181920
  1. //
  2. // Data+Extension.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/11/20.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. //ext Data
  10. extension Data {
  11. var hexString: String {
  12. return withUnsafeBytes {(bytes: UnsafePointer<UInt8>) -> String in
  13. let buffer = UnsafeBufferPointer(start: bytes, count: count)
  14. return buffer.map {String(format: "%02hhx", $0)}.reduce("", { $0 + $1 })
  15. }
  16. }
  17. }