Skip to content

Commit

Permalink
feat:done
Browse files Browse the repository at this point in the history
  • Loading branch information
0right0705 committed Feb 15, 2024
1 parent 69c4fd9 commit d1cb319
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 13 additions & 5 deletions AlwaysOnSize/AlwaysOnSizeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,36 @@ func getFreeSizeAsString() -> String {
}


func findFileSize() -> String {
func findFileSize() -> [String] {
let filePath = try? FileManager.default.contentsOfDirectory(at: .downloadsDirectory, includingPropertiesForKeys: [.fileSizeKey])

var fileSize : Double = 0

var dic : [String:Double] = [:]
var dicarr : [String] = []
do {
//return [FileAttributeKey : Any]
for file in filePath! {
print(file)

let attr = try FileManager.default.attributesOfItem(atPath: file.path)
fileSize = attr[FileAttributeKey.size] as! Double

//if you convert to NSDictionary, you can get file size old way as well.
let dict = attr as NSDictionary
fileSize = Double(dict.fileSize())
print(getFormatedNumberString(size: fileSize))
dic.updateValue(fileSize, forKey: file.path)
}
} catch {
print("Error: \(error)")
}
return getFormatedNumberString(size: fileSize)
var sortdic = dic.sorted { (first, second) in
return first.value > second.value

}
for i in sortdic {
dicarr.append(String(i.value))
print(i.value)
}
return dicarr
}


13 changes: 10 additions & 3 deletions AlwaysOnSize/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ import SwiftUI

struct ContentView: View {
@State var name : String = ""
var storage : String = getFreeSizeAsString()
var size : String = findFileSize()
@State var storage : String = getFreeSizeAsString()
var size : [String] = findFileSize()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text(storage)
Text(size)
Text(size[0])
}
.task {
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { (_) in
Text(storage)
}

timer.fire()
}
.padding()
}
Expand Down

0 comments on commit d1cb319

Please sign in to comment.