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>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>7E943A1C273211C200E7DDF4</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@ -7,6 +7,7 @@
import Foundation
import UIKit
import CoreData
struct K {
static let posColors = [
@ -23,4 +24,11 @@ struct K {
"oth": 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 {
@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
func calculateStatistics() {
print("count: \(flashCardAnswers.count)")
for answer in flashCardAnswers {
for answer in answers {
if answer.triesCount != 0 {
print("word: \(answer.word)")
print("tries: \(answer.triesCount)")
@ -25,16 +24,7 @@ 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 {
Text("Percentage: \(statistics)")

View File

@ -39,7 +39,7 @@ extension Binding {
struct FlashCardStack: View {
@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]
@State private var flashCards: [FlashCard] = []