Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created March 21, 2018 18:46
Show Gist options
  • Save vialyx/66ab9335f3ae76874edadc055a33328f to your computer and use it in GitHub Desktop.
Save vialyx/66ab9335f3ae76874edadc055a33328f to your computer and use it in GitHub Desktop.
import Foundation
let fileSizeInBytes: Int64 = 1924284
let byteFormatter = ByteCountFormatter()
print("Default settigs: \(byteFormatter.string(fromByteCount: fileSizeInBytes))")
// Default settigs: 1.9 MB
byteFormatter.allowedUnits = .useKB
print("Change allowedUnits settig: \(byteFormatter.string(fromByteCount: fileSizeInBytes))")
// Change allowedUnits settig: 1,924 KB
byteFormatter.allowedUnits = .useAll
byteFormatter.isAdaptive = false
print("Change isAdaptive settig: \(byteFormatter.string(fromByteCount: fileSizeInBytes))")
// Change isAdaptive settig: 1.92 MB
byteFormatter.includesUnit = false
print("Change includesUnit settig: \(byteFormatter.string(fromByteCount: fileSizeInBytes))")
// Change includesUnit settig: 1.92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment