Fix swift previews crash

This commit is contained in:
Avery Pace 2021-11-07 18:12:21 -05:00
parent 06c2d156c9
commit 6cd7dae538
4 changed files with 12 additions and 22 deletions

View File

@ -10,13 +10,5 @@
<integer>0</integer> <integer>0</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>7E943A1C273211C200E7DDF4</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict> </dict>
</plist> </plist>

View File

@ -7,6 +7,7 @@
import Foundation import Foundation
import UIKit import UIKit
import CoreData
struct K { struct K {
static let posColors = [ static let posColors = [
@ -23,4 +24,11 @@ struct K {
"oth": UIColor.systemBrown, "oth": UIColor.systemBrown,
"extra": UIColor.systemBrown "extra": UIColor.systemBrown
] ]
static var getFlashCardAnswersFetchRequest: NSFetchRequest<FlashCardAnswer> {
let request: NSFetchRequest<FlashCardAnswer> = FlashCardAnswer.fetchRequest()
request.sortDescriptors = []
return request
}
} }

View File

@ -10,13 +10,12 @@ import SwiftUI
struct FlashCardResultsView: View { struct FlashCardResultsView: View {
@Environment(\.managedObjectContext) private var viewContext @Environment(\.managedObjectContext) private var viewContext
@FetchRequest(entity:FlashCardAnswer.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \FlashCardAnswer.word, ascending: false)], predicate: NSPredicate(format: "word == %@", "a")) var flashCardAnswers: FetchedResults<FlashCardAnswer> @FetchRequest(fetchRequest: K.getFlashCardAnswersFetchRequest) var answers: FetchedResults<FlashCardAnswer>
@State private var statistics = 0.0 @State private var statistics = 0.0
func calculateStatistics() { func calculateStatistics() {
print("count: \(flashCardAnswers.count)") for answer in answers {
for answer in flashCardAnswers {
if answer.triesCount != 0 { if answer.triesCount != 0 {
print("word: \(answer.word)") print("word: \(answer.word)")
print("tries: \(answer.triesCount)") print("tries: \(answer.triesCount)")
@ -26,15 +25,6 @@ struct FlashCardResultsView: View {
} }
} }
// func calculateStatistics() {
// var correctAnswers = 0
// for answer in flashCardAnswers {
// if answer.correct {
// correctAnswers += 1
// }
// self.statistics = Double(correctAnswers) / Double(flashCardAnswers.count)
// }
// }
var body: some View { var body: some View {
Text("Percentage: \(statistics)") Text("Percentage: \(statistics)")

View File

@ -39,7 +39,7 @@ extension Binding {
struct FlashCardStack: View { struct FlashCardStack: View {
@Environment(\.managedObjectContext) private var viewContext @Environment(\.managedObjectContext) private var viewContext
@FetchRequest(entity:FlashCardAnswer.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \FlashCardAnswer.word, ascending: false)]) var flashCardAnswers: FetchedResults<FlashCardAnswer> @FetchRequest(fetchRequest: K.getFlashCardAnswersFetchRequest) var flashCardAnswers: FetchedResults<FlashCardAnswer>
var dictionary: [TokiDictEntry] var dictionary: [TokiDictEntry]
@State private var flashCards: [FlashCard] = [] @State private var flashCards: [FlashCard] = []