Mercurial > public > geoquiz
comparison GeoQuiz/Helpers/PlayedGamesList.swift @ 26:425078c01194
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 09 Nov 2022 10:30:01 +0100 |
parents | GeoQuiz/Components/PlayedGamesList.swift@b145c408f791 |
children |
comparison
equal
deleted
inserted
replaced
25:b3df0f5dc750 | 26:425078c01194 |
---|---|
1 // | |
2 // PlayedGamesList.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 23/10/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct PlayedGamesList: View { | |
11 @FetchRequest(sortDescriptors: [ | |
12 SortDescriptor(\.date, order: .reverse), | |
13 ]) var playedGames: FetchedResults<PlayedGame> | |
14 | |
15 @Environment(\.managedObjectContext) var moc | |
16 | |
17 var body: some View { | |
18 List { | |
19 ForEach(playedGames, id: \.id) { game in | |
20 RecentGame(game: game) | |
21 } | |
22 .onDelete{ indexSet in | |
23 CoreDataController.deleteGame(at: indexSet, from: playedGames, with: moc) | |
24 } | |
25 } | |
26 .navigationTitle("Played games") | |
27 .navigationBarTitleDisplayMode(.inline) | |
28 .toolbar { | |
29 EditButton() | |
30 } | |
31 } | |
32 } | |
33 | |
34 struct PlayedGamesList_Previews: PreviewProvider { | |
35 static var previews: some View { | |
36 NavigationView { | |
37 PlayedGamesList() | |
38 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) | |
39 } | |
40 } | |
41 } |