Refactor project structure and API
This commit is contained in:
23
Extensions/ByteFormatting.swift
Normal file
23
Extensions/ByteFormatting.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// ByteFormatting.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 01.04.25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Int {
|
||||
func toNiceBinaryUnit() -> String {
|
||||
let units = ["B", "KB", "MB", "GB", "TB", "PB"]
|
||||
var value = Double(self)
|
||||
var index = 0
|
||||
|
||||
while value >= 1024 && index < units.count - 1 {
|
||||
value /= 1024
|
||||
index += 1
|
||||
}
|
||||
|
||||
return String(format: "%.2f %@", value, units[index])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user