From cc032110d4eeb45d19a5df39b20b2ae5c7e85a6e Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 21 Jul 2026 21:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=AD=A3=E7=A1=AE=E7=8E=87=E7=BB=9F=E8=AE=A1=EF=BC=8C?= =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E6=8B=BC=E5=86=99=E9=AA=8C=E8=AF=81=E8=BF=BD?= =?UTF-8?q?=E8=B8=AA=E5=AF=B9=E9=94=99=E5=B9=B6=E8=AE=A1=E7=AE=97=E7=99=BE?= =?UTF-8?q?=E5=88=86=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- LearnEnglish/LearnEnglish/Models/LearnedStore.swift | 12 ++++++++++-- .../LearnEnglish/Views/HistoryViewController.swift | 2 +- .../LearnEnglish/Views/QuizViewController.swift | 2 +- LearnEnglish/LearnEnglish/Views/WordCardCell.swift | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/LearnEnglish/LearnEnglish/Models/LearnedStore.swift b/LearnEnglish/LearnEnglish/Models/LearnedStore.swift index 7841f50..303d8da 100644 --- a/LearnEnglish/LearnEnglish/Models/LearnedStore.swift +++ b/LearnEnglish/LearnEnglish/Models/LearnedStore.swift @@ -4,6 +4,11 @@ struct LearnedRecord: Codable { let word: Word var learnedAt: Date var count: Int = 1 + var correctCount: Int = 0 + + var accuracy: Int { + count > 0 ? Int(Double(correctCount) / Double(count) * 100) : 0 + } } final class LearnedStore { @@ -26,12 +31,15 @@ final class LearnedStore { } } - func record(_ word: Word) { + func record(_ word: Word, correct: Bool) { if let index = records.firstIndex(where: { $0.word.id == word.id }) { records[index].learnedAt = Date() records[index].count += 1 + if correct { records[index].correctCount += 1 } } else { - records.append(LearnedRecord(word: word, learnedAt: Date())) + var rec = LearnedRecord(word: word, learnedAt: Date()) + if correct { rec.correctCount = 1 } + records.append(rec) } } diff --git a/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift b/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift index 48d81e6..0c091ff 100644 --- a/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift @@ -67,7 +67,7 @@ final class HistoryViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! WordCardCell let record = sections[indexPath.section].items[indexPath.row] - cell.configure(with: record.word, count: record.count) + cell.configure(with: record.word, count: record.count, accuracy: record.accuracy) cell.onSpeak = { word in SpeechService.shared.speak(word.word) } diff --git a/LearnEnglish/LearnEnglish/Views/QuizViewController.swift b/LearnEnglish/LearnEnglish/Views/QuizViewController.swift index 55ff548..c14d645 100644 --- a/LearnEnglish/LearnEnglish/Views/QuizViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/QuizViewController.swift @@ -357,8 +357,8 @@ final class QuizViewController: UIViewController { private func submitSpelling(_ typed: String, for question: QuizQuestion) { guard selectedOption == nil else { return } selectedOption = typed - LearnedStore.shared.record(question.word) let correct = typed.lowercased() == question.answer.lowercased() + LearnedStore.shared.record(question.word, correct: correct) if !correct { wrongWords.append(question.word) } diff --git a/LearnEnglish/LearnEnglish/Views/WordCardCell.swift b/LearnEnglish/LearnEnglish/Views/WordCardCell.swift index 6a8fe10..a0e983a 100644 --- a/LearnEnglish/LearnEnglish/Views/WordCardCell.swift +++ b/LearnEnglish/LearnEnglish/Views/WordCardCell.swift @@ -92,9 +92,9 @@ final class WordCardCell: UITableViewCell { updateSpeakerState() } - func configure(with word: Word, count: Int) { + func configure(with word: Word, count: Int, accuracy: Int) { configure(with: word) - countLabel.text = "\(count)次" + countLabel.text = "\(count)次 · \(accuracy)%" countLabel.isHidden = false }