Mercurial > public > geoquiz
changeset 22:56add5561261
add mock data creation
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 26 Oct 2022 08:20:19 +0200 |
parents | b145c408f791 |
children | 02dcebb8cc4a |
files | GeoQuiz/Components/RecentGame.swift GeoQuiz/Logic/PersistenceController.swift GeoQuiz/ProfileModalView.swift |
diffstat | 3 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/GeoQuiz/Components/RecentGame.swift Tue Oct 25 15:30:01 2022 +0200 +++ b/GeoQuiz/Components/RecentGame.swift Wed Oct 26 08:20:19 2022 +0200 @@ -37,7 +37,7 @@ Text(gameInfo.name) .font(.headline) - Text("\(game.date ?? Date(), format: .dateTime)") + Text("\(game.date ?? Date(), format: .dateTime.day().month().year())") .font(.callout) .foregroundColor(.secondary) }
--- a/GeoQuiz/Logic/PersistenceController.swift Tue Oct 25 15:30:01 2022 +0200 +++ b/GeoQuiz/Logic/PersistenceController.swift Wed Oct 26 08:20:19 2022 +0200 @@ -16,7 +16,10 @@ static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext + + #if DEBUG createMockData(nil, viewContext) + #endif return result }() @@ -44,7 +47,9 @@ playedGame.type = GameType(rawValue: Int16.random(in: 0...3))! playedGame.score = Int32.random(in: 0...50) - playedGame.date = Date() + + let dayComponent = DateComponents(day: Int.random(in: -5...0)) + playedGame.date = Calendar.current.date(byAdding: dayComponent, to: Date()) if playedGame.type == .guessTheFlag || playedGame.type == .guessTheCapital { playedGame.correctAnswers = ["Bangladesh", "Belgium", "Burkina Faso", "Bermuda", "Jamaica"]