Skip to content

Instantly share code, notes, and snippets.

@AlexandrFadeev
Created October 15, 2017 19:54
Show Gist options
  • Save AlexandrFadeev/a1637a84dc7f491b41e8d842bee0f1b9 to your computer and use it in GitHub Desktop.
Save AlexandrFadeev/a1637a84dc7f491b41e8d842bee0f1b9 to your computer and use it in GitHub Desktop.
Covert bytes to megabytes in swift
let bcf = ByteCountFormatter()
bcf.allowedUnits = [.useMB] // optional: restricts the units to MB only
bcf.countStyle = .file
let string = bcf.string(fromByteCount: Int64(data.count))
print("formatted result: \(string)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment