diff --git a/Schedule ICTIS/Main/Views/CreatedClassView.swift b/Schedule ICTIS/Main/Views/CreatedClassView.swift index 8fb56fa..e36cd8b 100644 --- a/Schedule ICTIS/Main/Views/CreatedClassView.swift +++ b/Schedule ICTIS/Main/Views/CreatedClassView.swift @@ -8,34 +8,38 @@ import SwiftUI struct CreatedClassView: View { - let _class: ClassModel + @ObservedObject var _class: ClassModel + var provider = ClassProvider.shared var body: some View { - HStack(spacing: 10) { - VStack { - Text(getTimeString(_class.starttime)) - .font(.system(size: 15, weight: .regular)) - Text(getTimeString(_class.endtime)) - .font(.system(size: 15, weight: .regular)) + let existingCopy = try? provider.viewContext.existingObject(with: _class.objectID) + if let check = existingCopy { + HStack(spacing: 10) { + VStack { + Text(getTimeString(_class.starttime)) + .font(.system(size: 15, weight: .regular)) + Text(getTimeString(_class.endtime)) + .font(.system(size: 15, weight: .regular)) + } + .padding(.top, 7) + .padding(.bottom, 7) + .padding(.leading, 10) + Rectangle() + .frame(width: 2) + .frame(maxHeight: UIScreen.main.bounds.height - 18) + .padding(.top, 7) + .padding(.bottom, 7) + .foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online)) + Text(getSubjectName(_class.subject, _class.professor, _class.auditory)) + .font(.system(size: 18, weight: .regular)) + .padding(.top, 7) + .padding(.bottom, 7) + Spacer() } - .padding(.top, 7) - .padding(.bottom, 7) - .padding(.leading, 10) - Rectangle() - .frame(width: 2) - .frame(maxHeight: UIScreen.main.bounds.height - 18) - .padding(.top, 7) - .padding(.bottom, 7) - .foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online)) - Text(getSubjectName(_class.subject, _class.professor, _class.auditory)) - .font(.system(size: 18, weight: .regular)) - .padding(.top, 7) - .padding(.bottom, 7) - Spacer() + .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) + .background(Color.white) + .cornerRadius(20) + .shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2) } - .frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230) - .background(Color.white) - .cornerRadius(20) - .shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2) } } diff --git a/Schedule ICTIS/Main/Views/ScheduleView.swift b/Schedule ICTIS/Main/Views/ScheduleView.swift index 3725f72..ccc6f72 100644 --- a/Schedule ICTIS/Main/Views/ScheduleView.swift +++ b/Schedule ICTIS/Main/Views/ScheduleView.swift @@ -62,7 +62,6 @@ struct ScheduleView: View { CreatedClassView(_class: _class) .onTapGesture { selectedClass = _class - print(selectedClass) } } } diff --git a/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift b/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift index a2894af..0dfeb73 100644 --- a/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift +++ b/Schedule ICTIS/Main/Views/Sheets/CreateEditClassView.swift @@ -141,10 +141,10 @@ struct CreateEditClassView: View { Button { do { try delete(vm._class) + dismiss() } catch { print(error) } - dismiss() } label: { HStack { Spacer() @@ -194,7 +194,6 @@ struct CreateEditClassView: View { try context.save() } } - } } diff --git a/Schedule ICTIS/Provider/ClassProvider.swift b/Schedule ICTIS/Provider/ClassProvider.swift index f88ea6f..c1c831c 100644 --- a/Schedule ICTIS/Provider/ClassProvider.swift +++ b/Schedule ICTIS/Provider/ClassProvider.swift @@ -24,7 +24,10 @@ final class ClassProvider { } var newContext: NSManagedObjectContext { - persistentContainer.newBackgroundContext() + //persistentContainer.newBackgroundContext() + let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) + context.persistentStoreCoordinator = persistentContainer.persistentStoreCoordinator + return context } private init() {