diff --git a/OldNorseDictionary.xcodeproj/project.pbxproj b/OldNorseDictionary.xcodeproj/project.pbxproj index 5e2cfe1..6c9ccc2 100644 --- a/OldNorseDictionary.xcodeproj/project.pbxproj +++ b/OldNorseDictionary.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ A15829532A67DBCB00BD97D4 /* Case.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15829522A67DBCB00BD97D4 /* Case.swift */; }; A15829572A67DE7300BD97D4 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15829562A67DE7300BD97D4 /* Person.swift */; }; 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 */; }; 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 */; }; @@ -98,6 +100,7 @@ A15829522A67DBCB00BD97D4 /* Case.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Case.swift; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -187,6 +190,7 @@ A15829582A68249100BD97D4 /* Number.swift */, A1EED5F42AB4B04D00FDD617 /* Gender.swift */, A13F2D552B323072003B1692 /* Tense.swift */, + A15ECE872B5C58DE003BFDFF /* Mood.swift */, ); path = Models; sourceTree = ""; @@ -400,6 +404,7 @@ A1C92F8D2ABCBEEB0015F5C0 /* DynamicTable.swift in Sources */, A158294D2A66DDCB00BD97D4 /* WordDetailView.swift in Sources */, A15829512A66DE4600BD97D4 /* WordSearchController.swift in Sources */, + A15ECE882B5C58DE003BFDFF /* Mood.swift in Sources */, A15829572A67DE7300BD97D4 /* Person.swift in Sources */, A15829532A67DBCB00BD97D4 /* Case.swift in Sources */, A15829432A66BEF700BD97D4 /* Word.swift in Sources */, @@ -424,6 +429,7 @@ A1F6CDDA2A75A970006F020E /* WordSearchController.swift in Sources */, A13F2D572B323072003B1692 /* Tense.swift in Sources */, A1F6CDDD2A75AB1A006F020E /* Case.swift in Sources */, + A15ECE892B5C58DE003BFDFF /* Mood.swift in Sources */, A1F6CDDC2A75AB18006F020E /* Conjugation.swift in Sources */, A1F6CDDB2A75AB16006F020E /* Word.swift in Sources */, A1F2B8592A7672B4003EBF17 /* WordService.swift in Sources */, diff --git a/Source/Models/Mood.swift b/Source/Models/Mood.swift new file mode 100644 index 0000000..882aed5 --- /dev/null +++ b/Source/Models/Mood.swift @@ -0,0 +1,20 @@ +// +// Mood.swift +// OldNorseDictionary +// +// Created by Andrey Skurlatov on 20.1.24.. +// + +import Foundation + +enum Mood: String, CaseIterable, Codable { + case indicative + case subjunctive + + + func Title(reflexive: Bool) -> String { + var title = self.rawValue + + return title + } +} diff --git a/Source/Models/Tense.swift b/Source/Models/Tense.swift index 0c33646..416f5b9 100644 --- a/Source/Models/Tense.swift +++ b/Source/Models/Tense.swift @@ -10,4 +10,14 @@ import Foundation enum Tense: String, CaseIterable, Codable { case past case present + + func Title(reflexive: Bool) -> String { + var title = self.rawValue.capitalized + + if reflexive { + title = "Reflexive " + title + } + + return title + } } diff --git a/Source/Models/Word.swift b/Source/Models/Word.swift index 651a406..707a85d 100644 --- a/Source/Models/Word.swift +++ b/Source/Models/Word.swift @@ -1696,6 +1696,15 @@ struct Word: Codable, Identifiable { return genitiveCase } + func generateConjugation(person: Person, number: Number, tense: Tense, reflexive: Bool) -> String? { + if reflexive { + return generateConjugationReflexive(person: person, number: number, tense: tense) + } else { + return generateConjugationNonReflexive(person: person, number: number, tense: tense) + } + + } + func generateConjugationReflexive(person: Person, number: Number, tense: Tense) -> String? { switch tense { case .past: @@ -1773,7 +1782,7 @@ struct Word: Codable, Identifiable { } - func generateConjugation(person: Person, number: Number, tense: Tense) -> String? { + func generateConjugationNonReflexive(person: Person, number: Number, tense: Tense) -> String? { switch tense { case .past: return generateConjugationPast(person: person, number: number) diff --git a/Source/Services/WordService.swift b/Source/Services/WordService.swift index 9adb5be..43dabac 100644 --- a/Source/Services/WordService.swift +++ b/Source/Services/WordService.swift @@ -124,19 +124,19 @@ class WordService { // verbs - let firstSingularMatchesQuery = word.generateConjugation(person: .first, number: .singular, tense: .present)?.lowercased().contains(query) == true - let secondSingularMatchesQuery = word.generateConjugation(person: .second, number: .singular, tense: .present)?.lowercased().contains(query) == true - let thirdSingularMatchesQuery = word.generateConjugation(person: .third, number: .singular, tense: .present)?.lowercased().contains(query) == true - let firstPluralMatchesQuery = word.generateConjugation(person: .first, number: .plural, tense: .present)?.lowercased().contains(query) == true - let secondPluralMatchesQuery = word.generateConjugation(person: .second, number: .plural, tense: .present)?.lowercased().contains(query) == true - let thirdPluralMatchesQuery = word.generateConjugation(person: .third, number: .plural, tense: .present)?.lowercased().contains(query) == true - - let firstSingularMatchesQueryPast = word.generateConjugation(person: .first, number: .singular, tense: .past)?.lowercased().contains(query) == true - let secondSingularMatchesQueryPast = word.generateConjugation(person: .second, number: .singular, tense: .past)?.lowercased().contains(query) == true - let thirdSingularMatchesQueryPast = word.generateConjugation(person: .third, number: .singular, tense: .past)?.lowercased().contains(query) == true - let firstPluralMatchesQueryPast = word.generateConjugation(person: .first, number: .plural, tense: .past)?.lowercased().contains(query) == true - let secondPluralMatchesQueryPast = word.generateConjugation(person: .second, number: .plural, tense: .past)?.lowercased().contains(query) == true - let thirdPluralMatchesQueryPast = word.generateConjugation(person: .third, number: .plural, tense: .past)?.lowercased().contains(query) == true + let firstSingularMatchesQuery = word.generateConjugationNonReflexive(person: .first, number: .singular, tense: .present)?.lowercased().contains(query) == true + let secondSingularMatchesQuery = word.generateConjugationNonReflexive(person: .second, number: .singular, tense: .present)?.lowercased().contains(query) == true + let thirdSingularMatchesQuery = word.generateConjugationNonReflexive(person: .third, number: .singular, tense: .present)?.lowercased().contains(query) == true + let firstPluralMatchesQuery = word.generateConjugationNonReflexive(person: .first, number: .plural, tense: .present)?.lowercased().contains(query) == true + let secondPluralMatchesQuery = word.generateConjugationNonReflexive(person: .second, number: .plural, tense: .present)?.lowercased().contains(query) == true + let thirdPluralMatchesQuery = word.generateConjugationNonReflexive(person: .third, number: .plural, tense: .present)?.lowercased().contains(query) == true + + let firstSingularMatchesQueryPast = word.generateConjugationNonReflexive(person: .first, number: .singular, tense: .past)?.lowercased().contains(query) == true + let secondSingularMatchesQueryPast = word.generateConjugationNonReflexive(person: .second, number: .singular, tense: .past)?.lowercased().contains(query) == true + let thirdSingularMatchesQueryPast = word.generateConjugationNonReflexive(person: .third, number: .singular, tense: .past)?.lowercased().contains(query) == true + let firstPluralMatchesQueryPast = word.generateConjugationNonReflexive(person: .first, number: .plural, tense: .past)?.lowercased().contains(query) == true + let secondPluralMatchesQueryPast = word.generateConjugationNonReflexive(person: .second, number: .plural, tense: .past)?.lowercased().contains(query) == true + let thirdPluralMatchesQueryPast = word.generateConjugationNonReflexive(person: .third, number: .plural, tense: .past)?.lowercased().contains(query) == true // reflexive verbs let firstSingularMatchesQueryR = word.generateConjugationReflexive(person: .first, number: .singular, tense: .present)?.lowercased().contains(query) == true diff --git a/Source/Views/DynamicTableVerbs.swift b/Source/Views/DynamicTableVerbs.swift index a95bc8d..5401f04 100644 --- a/Source/Views/DynamicTableVerbs.swift +++ b/Source/Views/DynamicTableVerbs.swift @@ -3,43 +3,72 @@ import SwiftUI struct DynamicTableVerbs: View { let word: Word - var body: some View { - ScrollView(.horizontal, showsIndicators: true) { - VStack(alignment: .leading) { - // Main Headers + func Headers(tense: Tense, reflexive: Bool) -> some View { + Group { + 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) - 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("Present Tense") - .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) + Text(tense.Title(reflexive: reflexive)) + .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) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + let headerWidthValue = headerWidth(for: num) + Text(num.rawValue.capitalized) + .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } } + } + } + } + + + func Rows(tense: Tense, reflexive: Bool) -> some View { + ForEach(Person.allCases, id: \.rawValue) { p in + HStack(spacing: 0) { + Text(p.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) - 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) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - let headerWidthValue = headerWidth(for: num) - Text(num.rawValue.capitalized) - .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + if let wordWithConjunction = word.generateConjugation(person: p, number: num, tense: tense, reflexive: reflexive) { + Text(wordWithConjunction) + .frame(minWidth: headerWidth(for: num), maxWidth: .infinity) .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) .border(Color.black, width: 1) } } } + } + } + } + + var body: some View { + ScrollView(.horizontal, showsIndicators: true) { + VStack(alignment: .leading) { + // present tense + Headers(tense: .present, reflexive: false) HStack(spacing: 0) { Text("Imperative") @@ -60,117 +89,17 @@ struct DynamicTableVerbs: View { } } - // Rows - ForEach(Person.allCases, id: \.rawValue) { p in - HStack(spacing: 0) { - Text(p.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) { - if let wordWithConjunction = word.generateConjugation(person: p, number: num, tense: .present) { - Text(wordWithConjunction) - .frame(minWidth: headerWidth(for: num), maxWidth: .infinity) - .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("Past Tense") - .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) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - let headerWidthValue = headerWidth(for: num) - Text(num.rawValue.capitalized) - .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - } - } - - // Rows - ForEach(Person.allCases, id: \.rawValue) { p in - HStack(spacing: 0) { - Text(p.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) { - if let wordWithConjunction = word.generateConjugation(person: p, number: num, tense: .past) { - Text(wordWithConjunction) - .frame(minWidth: headerWidth(for: num), maxWidth: .infinity) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } - // Main Headers - - 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("Reflexive Present Tense") - .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) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - let headerWidthValue = headerWidth(for: num) - Text(num.rawValue.capitalized) - .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - } - } + Rows(tense: .present, reflexive: false) + + + // past tense + Headers(tense: .past, reflexive: false) + Rows(tense: .past, reflexive: false) + + // present tense reflexive + Headers(tense: .present, reflexive: true) + HStack(spacing: 0) { Text("Imperative") .frame(minWidth: 87, maxWidth: 87) @@ -190,82 +119,11 @@ struct DynamicTableVerbs: View { } } - // Rows - ForEach(Person.allCases, id: \.rawValue) { p in - HStack(spacing: 0) { - Text(p.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) { - if let wordWithConjunction = word.generateConjugationReflexive(person: p, number: num, tense: .present) { - Text(wordWithConjunction) - .frame(minWidth: headerWidth(for: num), maxWidth: .infinity) - .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("Reflexive Past Tense") - .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) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - let headerWidthValue = headerWidth(for: num) - Text(num.rawValue.capitalized) - .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - } - } + Rows(tense: .present, reflexive: true) - // Rows - ForEach(Person.allCases, id: \.rawValue) { p in - HStack(spacing: 0) { - Text(p.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) { - if let wordWithConjunction = word.generateConjugationReflexive(person: p, number: num, tense: .past) { - Text(wordWithConjunction) - .frame(minWidth: headerWidth(for: num), maxWidth: .infinity) - .padding(.vertical, 10) - .border(Color.black, width: 1) - } - } - } - } - } + // past tense reflexive + Headers(tense: .past, reflexive: true) + Rows(tense: .past, reflexive: true) } } }