-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swift
254 lines (224 loc) · 8.56 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import SwiftUI
// ExamAssignmentView
struct ExamAssignmentView: View {
@State private var showingAddExam = false
@State private var showingAddAssignment = false
@State private var showingActionSheet = false
@State private var examItems: [ExamItem] = []
@State private var assignmentItems: [AssignmentItem] = []
var body: some View {
VStack {
HStack {
Text("시험/과제")
.font(.largeTitle)
.fontWeight(.bold)
.padding()
Spacer()
NavigationLink(destination: SettingsView()) {
Image(systemName: "gearshape.fill")
.font(.headline)
.padding()
.foregroundColor(.black)
}
Button(action: {
showingActionSheet = true
}) {
Image(systemName: "plus")
.font(.headline)
.padding()
.foregroundColor(.black)
}
.actionSheet(isPresented: $showingActionSheet) {
ActionSheet(
title: Text("추가할 항목을 선택하세요"),
buttons: [
.default(Text("시험 추가")) {
showingAddExam = true
},
.default(Text("과제 추가")) {
showingAddAssignment = true
},
.cancel()
]
)
}
}
List {
Section(header: Text("시험")) {
ForEach(examItems) { exam in
NavigationLink(destination: ExamDetailView(exam: exam)) {
Text("\(exam.title) - \(exam.date.formatted(date: .abbreviated, time: .omitted))")
}
}
.onDelete(perform: deleteExam)
}
Section(header: Text("과제")) {
ForEach(assignmentItems) { assignment in
NavigationLink(destination: AssignmentDetailView(assignment: assignment)) {
HStack {
Text("\(assignment.title) - \(assignment.dueDate.formatted(date: .abbreviated, time: .omitted))")
Spacer()
if assignment.isPriority {
Image(systemName: "star.fill")
.foregroundColor(.yellow)
}
}
}
}
.onDelete(perform: deleteAssignment)
}
}
.listStyle(InsetGroupedListStyle())
.navigationTitle("시험/과제")
.sheet(isPresented: $showingAddExam) {
AddExamView(examItems: $examItems)
}
.sheet(isPresented: $showingAddAssignment) {
AddAssignmentView(assignmentItems: $assignmentItems)
}
}
}
private func deleteExam(at offsets: IndexSet) {
examItems.remove(atOffsets: offsets)
}
private func deleteAssignment(at offsets: IndexSet) {
assignmentItems.remove(atOffsets: offsets)
}
}
// ExamItem
struct ExamItem: Identifiable, Codable {
var id = UUID()
var title: String
var date: Date
}
// AssignmentItem
struct AssignmentItem: Identifiable, Codable {
var id = UUID()
var title: String
var subject: String
var dueDate: Date
var isPriority: Bool = false
var reminderDate: Date
var repeatTask: Bool
}
// AddExamView
struct AddExamView: View {
@Binding var examItems: [ExamItem]
@Environment(\.presentationMode) var presentationMode
@State private var title: String = ""
@State private var date: Date = Date()
var body: some View {
NavigationView {
Form {
Section(header: Text("시험 정보")) {
TextField("시험명", text: $title)
DatePicker("날짜", selection: $date, displayedComponents: [.date, .hourAndMinute])
}
Section {
Button("저장") {
let newItem = ExamItem(title: title, date: date)
examItems.append(newItem)
presentationMode.wrappedValue.dismiss()
}
}
}
.navigationBarTitle("시험 추가")
.navigationBarItems(trailing: Button("닫기") {
presentationMode.wrappedValue.dismiss()
})
}
}
}
// AddAssignmentView
struct AddAssignmentView: View {
@Binding var assignmentItems: [AssignmentItem]
@Environment(\.presentationMode) var presentationMode
@State private var title: String = ""
@State private var subject: String = ""
@State private var dueDate: Date = Date()
@State private var isPriority: Bool = false
@State private var reminderDate: Date = Date()
@State private var repeatTask: Bool = false
var body: some View {
NavigationView {
Form {
Section(header: Text("과제 정보")) {
TextField("과목명", text: $subject)
TextField("과제명", text: $title)
HStack {
Text("중요도")
Spacer()
Button(action: {
isPriority.toggle()
}) {
Image(systemName: isPriority ? "star.fill" : "star")
.foregroundColor(isPriority ? .yellow : .gray)
}
}
}
Section(header: Text("시간 설정")) {
DatePicker("마감일", selection: $dueDate, displayedComponents: [.date, .hourAndMinute])
DatePicker("알림 설정", selection: $reminderDate, displayedComponents: [.date, .hourAndMinute])
Toggle("반복", isOn: $repeatTask)
}
Section {
Button("저장") {
let newItem = AssignmentItem(
title: title,
subject: subject,
dueDate: dueDate,
isPriority: isPriority,
reminderDate: reminderDate,
repeatTask: repeatTask
)
assignmentItems.append(newItem)
assignmentItems.sort { $0.isPriority && !$1.isPriority }
presentationMode.wrappedValue.dismiss()
}
}
}
.navigationBarTitle("과제 추가")
.navigationBarItems(trailing: Button("닫기") {
presentationMode.wrappedValue.dismiss()
})
}
}
}
// ExamDetailView
struct ExamDetailView: View {
var exam: ExamItem
var body: some View {
VStack {
Text(exam.title)
.font(.largeTitle)
.padding()
Text("날짜: \(exam.date.formatted(date: .abbreviated, time: .shortened))")
.padding()
Spacer()
}
.navigationTitle("시험 상세")
}
}
// AssignmentDetailView
struct AssignmentDetailView: View {
var assignment: AssignmentItem
var body: some View {
VStack {
Text(assignment.title)
.font(.largeTitle)
.padding()
Text("과목: \(assignment.subject)")
Text("마감일: \(assignment.dueDate.formatted(date: .abbreviated, time: .shortened))")
if assignment.isPriority {
Text("중요도: 최우선")
}
Text("알림 설정: \(assignment.reminderDate.formatted(date: .abbreviated, time: .shortened))")
Text("반복: \(assignment.repeatTask ? "예" : "아니오")")
Spacer()
}
.navigationTitle("과제 상세")
}
}
#Preview {
ExamAssignmentView()
}