-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
75 lines (69 loc) · 2.35 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ContentView.swift
// AlwaysOnSize
//
// Created by 최영우 on 2024. 2. 14..
//
import SwiftUI
struct ContentView: View {
@State private var fileInformations: [FileInformation] = []
@State private var storage: String = ""
@State private var size: [String] = []
private let timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text(storage)
Text(size.first ?? "")
List(fileInformations.indices, id: \.self) { index in
Toggle(isOn: $fileInformations[index].isChecked) {
VStack(alignment: .leading) {
Text("Filename: \(fileInformations[index].fileName)")
Text("Filesize: \(getFormatedNumberString(size: fileInformations[index].fileSize))")
Text("Path: \(fileInformations[index].path)")
}
}
}
Text("Total Checked File Size:\n \(totalCheckedFileSize(fileInformations: fileInformations)) bytes")
Button(action: {
deleteFiles(fileInformations: fileInformations)
fileInformations = findFileInformations()
storage = getFreeSizeAsString()
size = findFileSize()
}, label: {
Text("Delete")
})
.padding()
}
// 초기 화면값
.onAppear {
fileInformations = findFileInformations()
storage = getFreeSizeAsString()
size = findFileSize()
}
// 3초마다 storage변화 확인
.onReceive(timer) { _ in
fileInformations = findFileInformations()
storage = getFreeSizeAsString()
size = findFileSize()
}
.padding()
}
}
//struct ContentView: View {
// @State var name : String = ""
// var storage : String = getFreeSizeAsString()
// var size : String = findFileSize()
// var body: some View {
// VStack {
// Image(systemName: "globe")
// .imageScale(.large)
// .foregroundStyle(.tint)
// Text(storage)
// Text(size)
// }
// .padding()
// }
//}