66//
77
88import SwiftUI
9+ import SwiftData
910
1011struct SettingView : View {
11- @State private var selectedAlarmTime = Date . now
12+ @Environment ( \. modelContext) private var modelContext
13+ @Query var user : [ UserInfo ]
14+
15+ @State private var selectedAlarmTime = Date ( )
1216 @State private var isSoundOn = false
13- // @State private var selectedPill = 0
17+ // @State private var selectedPill = 0
1418 @Binding var selectedPill : PillInfo ?
1519 @State private var isShowingPills = false
1620 @Binding var showingMedicineSheet : Bool
1721
1822
19-
20-
21-
22- // let pills = [(name: "야즈", type: "24일/4일"), (name: "머쉬론", type: "21일/7일")]
23-
2423 var body : some View {
2524 NavigationStack {
2625 Form {
@@ -40,7 +39,7 @@ struct SettingView: View {
4039
4140 NavigationLink ( destination: MedicineSheetView ( showingMedicineSheet: $showingMedicineSheet, selectedPill: $selectedPill) ) {
4241 HStack {
43- Text ( " Select Pill " )
42+ Text ( " 약 선택 " )
4443 Spacer ( )
4544 if let pill = selectedPill {
4645 Text ( pill. pillName)
@@ -55,11 +54,29 @@ struct SettingView: View {
5554
5655 Section ( " 알림 " ) {
5756 DatePicker ( " 시간 " , selection: $selectedAlarmTime, displayedComponents: . hourAndMinute)
57+ . onChange ( of: selectedAlarmTime) { oldValue, newValue in
58+ let newValueToString = Config . DateToString ( date: newValue, format: Hourformat)
59+ user. first? . scheduleTime = newValueToString
60+ print ( newValueToString)
61+ }
5862
5963 Toggle ( " 알람 " , isOn: $isSoundOn)
64+ . onChange ( of: isSoundOn) { oldValue, newValueAlarm in
65+ user. first? . isAlarm = newValueAlarm
66+ }
67+ // Optional, unWrapped
6068
6169 }
6270 }
71+ . onAppear {
72+ if let userInfo = user. first {
73+ selectedPill = userInfo. curPill? . pillInfo
74+ selectedAlarmTime = Config . StringToDate ( dateString: userInfo. scheduleTime, format: Hourformat) !
75+ // selectedAlarmTime = Config.DateToString(date: selectedAlarmTime, format: Hourformat)
76+ isSoundOn = userInfo. isAlarm
77+ }
78+
79+ }
6380 . navigationTitle ( " Settings " )
6481 // .sheet(isPresented: $isShowingPills, content: {
6582 // Text("Pills")
0 commit comments