Skip to content

Commit

Permalink
Restore the barebone app setup
Browse files Browse the repository at this point in the history
Leave the AppView(initialOrdering:) initializer, though, so that readers can get some inspiration.
  • Loading branch information
groue committed Apr 10, 2021
1 parent fd61a5f commit a5ffc52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import SwiftUI

@main
struct GRDBCombineDemoApp: App {
@State var initialOrdering: PlayerRequest.Ordering = .byName

var body: some Scene {
WindowGroup {
AppView(initialOrdering: initialOrdering)
.environment(\.appDatabase, AppDatabase.shared)
.onAppear {
initialOrdering = .byScore
}
AppView().environment(\.appDatabase, AppDatabase.shared)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ struct AppView: View {
@Environment(\.appDatabase) private var appDatabase

/// The `players` property is kept up-to-date with the list of players.
@Query(PlayerRequest(ordering: .byName)) private var players: [Player]
@Query(PlayerRequest(ordering: .byScore)) private var players: [Player]

/// Tracks the presentation of the player creation sheet.
@State private var newPlayerIsPresented = false

init(initialOrdering: PlayerRequest.Ordering) {
// Example to update a query on init
_players = Query(PlayerRequest(ordering: initialOrdering))
}
// If you want to define the query on initialization, you will prefer:
//
// @Query<PlayerRequest> private var players: [Player]
//
// init(initialOrdering: PlayerRequest.Ordering) {
// _players = Query(PlayerRequest(ordering: initialOrdering))
// }

var body: some View {
NavigationView {
Expand Down Expand Up @@ -89,10 +92,10 @@ struct AppView_Previews: PreviewProvider {
static var previews: some View {
Group {
// Preview a database of random players
AppView(initialOrdering: .byScore).environment(\.appDatabase, .random())
AppView().environment(\.appDatabase, .random())

// Preview an empty database
AppView(initialOrdering: .byScore).environment(\.appDatabase, .empty())
AppView().environment(\.appDatabase, .empty())
}
}
}

0 comments on commit a5ffc52

Please sign in to comment.