From a3217e63c55c6ac6b42b0d25bbed69ce1adcb8ba Mon Sep 17 00:00:00 2001 From: Andrew Skurlatov Date: Sat, 20 Jan 2024 22:04:29 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(project.pbxproj):=20add=20?= =?UTF-8?q?Formation.swift=20to=20project=20file=20=F0=9F=94=A7=20chore(pr?= =?UTF-8?q?oject.pbxproj):=20add=20Formation.swift=20to=20project=20file?= =?UTF-8?q?=20=F0=9F=94=A7=20chore(Formation.swift):=20add=20Formation=20e?= =?UTF-8?q?num=20with=20cases=20and=20Title()=20function=20=F0=9F=94=A7=20?= =?UTF-8?q?chore(Word.swift):=20add=20generateAdjective()=20function=20to?= =?UTF-8?q?=20generate=20adjective=20based=20on=20Formation=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(DynamicTable.swift): add formation parameter to Headers and Rows functions ✨ feat(DynamicTable.swift): add support for different formations in Headers and Rows functions --- OldNorseDictionary.xcodeproj/project.pbxproj | 6 + Source/Models/Formation.swift | 19 ++ Source/Models/Word.swift | 16 + Source/Views/DynamicTable.swift | 309 ++++--------------- 4 files changed, 109 insertions(+), 241 deletions(-) diff --git a/OldNorseDictionary.xcodeproj/project.pbxproj b/OldNorseDictionary.xcodeproj/project.pbxproj index 6c9ccc2..6d5e5dc 100644 --- a/OldNorseDictionary.xcodeproj/project.pbxproj +++ b/OldNorseDictionary.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ A15829592A68249100BD97D4 /* Number.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15829582A68249100BD97D4 /* Number.swift */; }; A15ECE882B5C58DE003BFDFF /* Mood.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15ECE872B5C58DE003BFDFF /* Mood.swift */; }; A15ECE892B5C58DE003BFDFF /* Mood.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15ECE872B5C58DE003BFDFF /* Mood.swift */; }; + A15ECE8B2B5C6657003BFDFF /* Formation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15ECE8A2B5C6657003BFDFF /* Formation.swift */; }; + A15ECE8C2B5C6657003BFDFF /* Formation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15ECE8A2B5C6657003BFDFF /* Formation.swift */; }; A1C92F8D2ABCBEEB0015F5C0 /* DynamicTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1C92F8C2ABCBEEB0015F5C0 /* DynamicTable.swift */; }; A1EED5F52AB4B04D00FDD617 /* Gender.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1EED5F42AB4B04D00FDD617 /* Gender.swift */; }; A1EED5F62AB4B04D00FDD617 /* Gender.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1EED5F42AB4B04D00FDD617 /* Gender.swift */; }; @@ -101,6 +103,7 @@ A15829562A67DE7300BD97D4 /* Person.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; A15829582A68249100BD97D4 /* Number.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Number.swift; sourceTree = ""; }; A15ECE872B5C58DE003BFDFF /* Mood.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mood.swift; sourceTree = ""; }; + A15ECE8A2B5C6657003BFDFF /* Formation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formation.swift; sourceTree = ""; }; A1C92F8C2ABCBEEB0015F5C0 /* DynamicTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicTable.swift; sourceTree = ""; }; A1EED5F42AB4B04D00FDD617 /* Gender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gender.swift; sourceTree = ""; }; A1F2B8502A76696F003EBF17 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -191,6 +194,7 @@ A1EED5F42AB4B04D00FDD617 /* Gender.swift */, A13F2D552B323072003B1692 /* Tense.swift */, A15ECE872B5C58DE003BFDFF /* Mood.swift */, + A15ECE8A2B5C6657003BFDFF /* Formation.swift */, ); path = Models; sourceTree = ""; @@ -403,6 +407,7 @@ A158294F2A66DE0500BD97D4 /* WordSearchView.swift in Sources */, A1C92F8D2ABCBEEB0015F5C0 /* DynamicTable.swift in Sources */, A158294D2A66DDCB00BD97D4 /* WordDetailView.swift in Sources */, + A15ECE8B2B5C6657003BFDFF /* Formation.swift in Sources */, A15829512A66DE4600BD97D4 /* WordSearchController.swift in Sources */, A15ECE882B5C58DE003BFDFF /* Mood.swift in Sources */, A15829572A67DE7300BD97D4 /* Person.swift in Sources */, @@ -433,6 +438,7 @@ A1F6CDDC2A75AB18006F020E /* Conjugation.swift in Sources */, A1F6CDDB2A75AB16006F020E /* Word.swift in Sources */, A1F2B8592A7672B4003EBF17 /* WordService.swift in Sources */, + A15ECE8C2B5C6657003BFDFF /* Formation.swift in Sources */, A1EED5F62AB4B04D00FDD617 /* Gender.swift in Sources */, A1F6CDDE2A75AB1C006F020E /* Person.swift in Sources */, A1F6CDB02A75A743006F020E /* WordListView.swift in Sources */, diff --git a/Source/Models/Formation.swift b/Source/Models/Formation.swift index 70b8cac..29f57cc 100644 --- a/Source/Models/Formation.swift +++ b/Source/Models/Formation.swift @@ -6,3 +6,22 @@ // import Foundation + +enum Formation: String, CaseIterable, Codable { + case strong + case weak + case comparative + case comparisonStrong + case comparisonWeak + + func Title() -> String { + switch self { + case .comparisonStrong: + return "Comparison Strong" + case .comparisonWeak: + return "Comparison Weak" + default: + return rawValue.capitalized + } + } +} diff --git a/Source/Models/Word.swift b/Source/Models/Word.swift index 707a85d..3864bfc 100644 --- a/Source/Models/Word.swift +++ b/Source/Models/Word.swift @@ -64,6 +64,22 @@ struct Word: Codable, Identifiable { var id = UUID() + + func generateAdjective(number: Number, gender: Gender, caseAdjective: Case, formation: Formation) -> String? { + switch formation { + case .strong: + return generateCase(wordCase: caseAdjective, number: number, gender: gender) + case .weak: + return generateWeakAdjective(number: number, gender: gender, caseWeak: caseAdjective) + case .comparative: + return generateComparativeAdjective(number: number, gender: gender, caseWeak: caseAdjective) + case .comparisonStrong: + return generateComparisonStrongAdjective(number: number, gender: gender, caseStrong: caseAdjective) + case .comparisonWeak: + return generateComparisonWeakAdjective(number: number, gender: gender, caseWeak: caseAdjective) + } + } + func generateComparisonStrongAdjective(number: Number, gender: Gender, caseStrong: Case) -> String? { if type != .adjective { return nil diff --git a/Source/Views/DynamicTable.swift b/Source/Views/DynamicTable.swift index 10cbee3..e69125d 100644 --- a/Source/Views/DynamicTable.swift +++ b/Source/Views/DynamicTable.swift @@ -4,8 +4,24 @@ struct DynamicTable: View { let word: Word - func Headers() -> some View { + func Headers(formation: Formation) -> some View { Group { + if word.type == .adjective { + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text(formation.Title()) + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + } + HStack(spacing: 0) { Text("") .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) @@ -49,262 +65,73 @@ struct DynamicTable: View { } } - - var body: some View { - ScrollView(.horizontal, showsIndicators: true) { - VStack(alignment: .leading) { - if word.type == .adjective { - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - Text("Strong Inflection") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - } - - Headers() - - // Rows - ForEach(Case.allCases, id: \.rawValue) { c in - HStack(spacing: 0) { - Text(c.rawValue.capitalized) - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .border(Color.black, width: 1) - .background(Color.gray.opacity(0.2)) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - if word.type == .noun { - if let wordWithCase = word.generateNounCase(nounCase: c, number: num, article: false) { - Text("\(wordWithCase)" + withArticle(c: c, num: num)!) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } else { - if let wordWithCase = word.generateCase(wordCase: c, number: num, gender: gen) { - Text(wordWithCase) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } - } - } - } + func Rows(formation: Formation) -> some View { + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) - if word.type == .adjective { - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - Text("Weak Inflection") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - - // Main Headers - Headers() - - // Rows - ForEach(Case.allCases, id: \.rawValue) { c in - HStack(spacing: 0) { - Text(c.rawValue.capitalized) - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .border(Color.black, width: 1) - .background(Color.gray.opacity(0.2)) - - ForEach(Number.allCases, id: \.rawValue) { num in - if num == .plural { - if let weakAdjective = word.generateWeakAdjective(number: num, gender: .any, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: 261, maxWidth: 261) + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if word.type == .noun { + if let wordWithCase = word.generateNounCase(nounCase: c, number: num, article: false) { + Text("\(wordWithCase)" + withArticle(c: c, num: num)!) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) .padding(.vertical, 10) .border(Color.black, width: 1) } - } else { - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - if let weakAdjective = word.generateWeakAdjective(number: num, gender: gen, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } - } - } - } - - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - Text("Comparative") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - - // Main Headers - Headers() - - // Rows - ForEach(Case.allCases, id: \.rawValue) { c in - HStack(spacing: 0) { - Text(c.rawValue.capitalized) - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .border(Color.black, width: 1) - .background(Color.gray.opacity(0.2)) - - ForEach(Number.allCases, id: \.rawValue) { num in - if num == .plural { - if let weakAdjective = word.generateComparativeAdjective(number: num, gender: .any, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: 261, maxWidth: 261) + } else if word.type == .adjective && formation != .strong { + if let wordWithCase = word.generateAdjective(number: num, gender: gen, caseAdjective: c, formation: formation) { + Text(wordWithCase) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) .padding(.vertical, 10) .border(Color.black, width: 1) } } else { - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - if let weakAdjective = word.generateComparativeAdjective(number: num, gender: gen, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } - } - } - } - - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - Text("Comparison Strong") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - - // Main Headers - Headers() - - // Rows - ForEach(Case.allCases, id: \.rawValue) { c in - HStack(spacing: 0) { - Text(c.rawValue.capitalized) - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .border(Color.black, width: 1) - .background(Color.gray.opacity(0.2)) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - if let wordWithCase = word.generateComparisonStrongAdjective(number: num, gender: gen, caseStrong: c) { - Text(wordWithCase) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } + if let wordWithCase = word.generateCase(wordCase: c, number: num, gender: gen) { + Text(wordWithCase) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) } } } } } + } + } + } + } + + + var body: some View { + ScrollView(.horizontal, showsIndicators: true) { + VStack(alignment: .leading) { + + Headers(formation: .strong) + Rows(formation: .strong) + + if word.type == .adjective { + // Weak + Headers(formation: .weak) + Rows(formation: .weak) - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - Text("Comparison Weak") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } + // Comparative + Headers(formation: .comparative) + Rows(formation: .comparative) - // Main Headers - Headers() + // Comparison Strong + Headers(formation: .comparisonStrong) + Rows(formation: .comparisonStrong) - // Rows - ForEach(Case.allCases, id: \.rawValue) { c in - HStack(spacing: 0) { - Text(c.rawValue.capitalized) - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .border(Color.black, width: 1) - .background(Color.gray.opacity(0.2)) - - ForEach(Number.allCases, id: \.rawValue) { num in - if num == .plural { - if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: .any, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: 261, maxWidth: 261) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } else { - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: gen, caseWeak: c) { - Text(weakAdjective) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } - } - } - } + // Comparison Weak + Headers(formation: .comparisonWeak) + Rows(formation: .comparisonWeak) } } }