From d192d6e334b2e519dad038095fc75dbddf686073 Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Tue, 18 Jan 2022 20:23:35 +0300 Subject: [PATCH] Refactoring everything --- GradeMapper.xcodeproj/project.pbxproj | 10 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 18 +++ Shared/ContentView.swift | 83 +++++++++---- Shared/GradeMapperApp.swift | 116 ++++-------------- Shared/SubjectView.swift | 67 ---------- 5 files changed, 108 insertions(+), 186 deletions(-) delete mode 100644 Shared/SubjectView.swift diff --git a/GradeMapper.xcodeproj/project.pbxproj b/GradeMapper.xcodeproj/project.pbxproj index 8912e99..6fc21d1 100644 --- a/GradeMapper.xcodeproj/project.pbxproj +++ b/GradeMapper.xcodeproj/project.pbxproj @@ -7,14 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 4F7E91CD279615A200CB18B7 /* SubjectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7E91CC279615A200CB18B7 /* SubjectView.swift */; }; 4FEB3F0F2795DFE90005C604 /* GradeMapperApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */; }; 4FEB3F112795DFE90005C604 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEB3F002795DFE80005C604 /* ContentView.swift */; }; 4FEB3F132795DFE90005C604 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FEB3F012795DFE90005C604 /* Assets.xcassets */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 4F7E91CC279615A200CB18B7 /* SubjectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubjectView.swift; sourceTree = ""; }; 4FD40DBC279702A900A5A6D2 /* GradeMapper (iOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "GradeMapper (iOS).entitlements"; sourceTree = ""; }; 4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradeMapperApp.swift; sourceTree = ""; }; 4FEB3F002795DFE80005C604 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -50,7 +48,6 @@ 4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */, 4FEB3F002795DFE80005C604 /* ContentView.swift */, 4FEB3F012795DFE90005C604 /* Assets.xcassets */, - 4F7E91CC279615A200CB18B7 /* SubjectView.swift */, ); path = Shared; sourceTree = ""; @@ -141,7 +138,6 @@ buildActionMask = 2147483647; files = ( 4FEB3F112795DFE90005C604 /* ContentView.swift in Sources */, - 4F7E91CD279615A200CB18B7 /* SubjectView.swift in Sources */, 4FEB3F0F2795DFE90005C604 /* GradeMapperApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -269,6 +265,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = F5PQ7AR4DP; + "ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; @@ -289,7 +286,7 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,6"; }; name = Debug; }; @@ -302,6 +299,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = F5PQ7AR4DP; + "ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; @@ -322,7 +320,7 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,6"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/GradeMapper.xcodeproj/xcuserdata/ivabus.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/GradeMapper.xcodeproj/xcuserdata/ivabus.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 6df4a0c..8693397 100644 --- a/GradeMapper.xcodeproj/xcuserdata/ivabus.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/GradeMapper.xcodeproj/xcuserdata/ivabus.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,4 +3,22 @@ uuid = "1FA12096-94D4-4153-9D70-423E3C4922F7" type = "1" version = "2.0"> + + + + + + diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift index 1333bc3..5049971 100644 --- a/Shared/ContentView.swift +++ b/Shared/ContentView.swift @@ -1,36 +1,71 @@ // -// ContentView.swift -// Shared +// SubjectView.swift +// GradeMapper // -// Created by Иван Бущик on 17.01.2022. +// Created by Иван Бущик on 18.01.2022. // import SwiftUI +enum Grade: Int, Identifiable, CaseIterable{ + case One = 1 + case Two = 2 + case Three = 3 + case Four = 4 + case Five = 5 -struct ContentView: View{ - var body: some View { - VStack(alignment: .center) { - Text("GradeMapper") - .font(.largeTitle) - .fontWeight(.heavy) - .multilineTextAlignment(.center) - NavigationView { - List{ - ForEach(subjectsNames, id: \.self) { - subjectName in NavigationLink("\(subjectName)", destination: SubjectView(name: subjectName)) - } - } - } - }.padding([.leading, .top], 5.0) - } + var id: Int { self.rawValue } } + +struct ContentView: View { + var counter = counters() + @State var sr: Double = 0 + @State private var selectedGrade = Grade.One + @State var selectedTypeOfGrade = "Контрольная работа" + + var body: some View { + Text("GradeMapper") + .font(.largeTitle) + .fontWeight(.heavy) + .multilineTextAlignment(.center) + .padding(.top, -75) + VStack(alignment: .center, spacing: 75){ + VStack(alignment: .leading, spacing: 30){ + Picker("Тип оценки", selection: $selectedTypeOfGrade){ + ForEach([String](coof.keys), id: \.self) { + subjectSN in Text("\(subjectSN)") + } + }.pickerStyle(.wheel) + VStack{ + Picker("Оценка", selection: $selectedGrade){ + ForEach(Grade.allCases, id: \.self) { + currGrade in Text("\(currGrade.rawValue)") + } + } + }.pickerStyle(.segmented).padding(.horizontal, 20) + }.padding(.top, 100) + Button ("Добавить оценку"){ + counter.multiplier = coof[selectedTypeOfGrade]! + counter.gradesWeighted += Double(selectedGrade.rawValue) * counter.multiplier + counter.weightsSum += counter.multiplier + self.sr = (counter.gradesWeighted / counter.weightsSum) + }.buttonStyle(.borderedProminent) + Text(String("Средний балл: \(self.sr)")) + .fontWeight(.bold) + Button ("Очистить"){ + counter.multiplier = 1.5 + counter.gradesWeighted = 0 + counter.weightsSum = 0 + self.sr = 0 + }.buttonStyle(.borderedProminent) + } + .padding(.top, -155.0) + + + } +} struct ContentView_Previews: PreviewProvider { - static var previews: some View { + static var previews: some View { ContentView() } } - - - - diff --git a/Shared/GradeMapperApp.swift b/Shared/GradeMapperApp.swift index 6747ef6..e3d7f86 100644 --- a/Shared/GradeMapperApp.swift +++ b/Shared/GradeMapperApp.swift @@ -7,39 +7,17 @@ import SwiftUI -class helpMe{ +class counters{ var multiplier: Double - var subjectName: String - var subjectSubName: String - var grade: Int - var sum: Double - var sr: Double var gradesWeighted: Double = 0 var weightsSum: Double = 0 - var history: [Int] init(){ - self.multiplier = 1.5 - self.subjectName = "Русский язык" - self.subjectSubName = "Контрольная работа" + self.multiplier = 1.0 self.gradesWeighted = 0 self.weightsSum = 0 - self.sr = 0 - self.sum = 0 - self.grade = 0 - self.history = [] } - func set(n1: String, n2: String) -> Void{ - self.multiplier = subjects[n1]![n2]! - self.subjectName = n1 - self.subjectSubName = n2 - } - func setGrade(grade: Int){ - self.grade = grade - } - } - @main struct GradeMapperApp: App { var body: some Scene { @@ -49,69 +27,29 @@ struct GradeMapperApp: App { } } -var subjects: [String : [String : Double]] = [ - "Русский язык": [ - "Контрольная работа": 1.5, - "Контрольный диктант": 1.5, - "Административная контрольная работа": 1.5, - "Словарный диктант": 1.4, - "Домашнее сочинение": 1.4, - "Изложение": 1.4, - "Проверочная работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Тест": 1.0, - "Сочинение": 1.0, - "Домашняя работа": 1.0 - ], "Литература": [ - "Контрольная работа": 1.5, - "Классное сочинение": 1.5, - "Домашнее сочинение": 1.4, - "Проверочная работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Тест": 1.0, - "Сочинение": 1.0, - "Домашняя работа": 1.0 - ], "Алгебрa": [ - "Контрольная работа": 1.5, - "Административная контрольная работа": 1.5, - "Контрольная практическая работа": 1.5, - "Зачёт": 1.5, - "Проверочная работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Домашняя работа": 1.0 - ], "Геометрия": [ - "Контрольная работа": 1.5, - "Административная контрольная работа": 1.5, - "Контрольная практическая работа": 1.5, - "Зачёт": 1.5, - "Проверочная работа": 1.3, - "Практическая работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Домашняя работа": 1.0 - ], "Физика": [ - "Контрольная работа": 1.5, - "Зачёт": 1.5, - "Проверочная работа": 1.3, - "Практическая работа": 1.3, - "Срезовая работа": 1.3, - "Лабораторная работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Тест": 1.0, - "Домашняя работа": 1.0 - ], "Информатика": [ - "Контрольная работа": 1.5, - "Зачёт": 1.5, - "Проверочная работа": 1.3, - "Практическая работа": 1.3, - "Самостоятельная работа": 1.2, - "Работа на уроке": 1.0, - "Домашняя работа": 1.0 - ] +var coof = [ + "Работа на уроке": 1.0, + "Тест": 1.0, + "Чтение наизусть": 1.0, + "Сочинение": 1.0, + "Дистанционный урок": 1.0, + "Электронное обучение": 1.0, + "Ведение тетради": 1.0, + "Викторина": 1.0, + "Работа над ошибками": 1.0, + "Самостоятельная работа": 1.2, + "Проверочная работа": 1.3, + "Практическая работа": 1.3, + "Лабораторная работа": 1.3, + "Срезовая работа": 1.3, + "Словарный диктант": 1.4, + "Домашнее сочинение": 1.4, + "Аудирование": 1.4, + "Изложение": 1.4, + "Контрольная работа": 1.5, + "Контрольный диктант": 1.5, + "Контрольная практическая работа": 1.5, + "Административная к.р.": 1.5, + "Зачёт": 1.5, + "Классное сочинение": 1.5 ] - -var subjectsNames: [String] = [String](subjects.keys) diff --git a/Shared/SubjectView.swift b/Shared/SubjectView.swift deleted file mode 100644 index f88ac91..0000000 --- a/Shared/SubjectView.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// SubjectView.swift -// GradeMapper -// -// Created by Иван Бущик on 18.01.2022. -// - -import SwiftUI -enum Grade: Int, Identifiable, CaseIterable{ - case One = 1 - case Two = 2 - case Three = 3 - case Four = 4 - case Five = 5 - - var id: Int { self.rawValue } -} - - -struct SubjectView: View { - var ow = helpMe() - @State var srr: Double = 0 - var name: String - @State private var selectedGrade = Grade.One - @State var selectedTypeOfGrade = "Контрольная работа" - - var body: some View { - var current = subjects[name]! - VStack(alignment: .center, spacing: 75){ - Text("\(name)") - .font(.title) - .fontWeight(.black) - .multilineTextAlignment(.center) - VStack(alignment: .leading, spacing: 30){ - Picker("Тип оценки", selection: $selectedTypeOfGrade){ - ForEach([String](subjects[name]!.keys), id: \.self) { - subjectSN in Text("\(subjectSN)") - } - }.pickerStyle(.wheel) - VStack{ - Picker("Оценка", selection: $selectedGrade){ - ForEach(Grade.allCases, id: \.self) { - currGrade in Text("\(currGrade.rawValue)") - } - } - }.pickerStyle(.segmented) - } - Button ("Добавить оценку"){ - ow.multiplier = current[selectedTypeOfGrade]! - ow.gradesWeighted += Double(selectedGrade.rawValue) * ow.multiplier - ow.weightsSum += ow.multiplier - ow.sr = (ow.gradesWeighted / ow.weightsSum) - print(ow.sr) - print(ow.multiplier) - self.srr = ow.sr - }.buttonStyle(.borderedProminent) - Text(String("Средний балл: \(self.srr)")) - .fontWeight(.bold) - } - .padding(.top, -155.0) - } -} -struct SubjectView_Previews: PreviewProvider { - static var previews: some View { - SubjectView(name: "Русский язык") - } -}