Skip to content

Commit 69093a2

Browse files
committed
added formattedFileSize
1 parent 6c60909 commit 69093a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

MacImageManager/MacImageManager/Models/FileItem.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@ struct FileItem: Identifiable, Hashable {
1818
let isDirectory: Bool
1919
let fileSize: Int
2020
let modificationDate: Date
21+
22+
var formattedFileSize: String {
23+
if fileSize < 1024 {
24+
return "\(fileSize) B"
25+
}
26+
let kb = Double(fileSize) / 1024.0
27+
if kb < 1024 {
28+
return String(format: "%.1f KB", kb)
29+
}
30+
let mb = kb / 1024.0
31+
if mb < 1024 {
32+
return String(format: "%.1f MB", mb)
33+
}
34+
let gb = mb / 1024.0
35+
return String(format: "%.2f GB", gb)
36+
}
2137
}

0 commit comments

Comments
 (0)