Hello Swift community and GRDB users,
I've released a new package: GRDBQuery. It provides a reusable @Query
property wrapper that feeds SwiftUI views with fresh database content:
import GRDBQuery
import SwiftUI
/// A view that displays an always up-to-date
/// list of players in the database.
struct PlayerList: View {
@Query(AllPlayers())
var players: [Player]
var body: some View {
List(players) { player in
Text(player.name)
}
}
}
In a way, @Query
is for GRDB what @FetchRequest
is for Core Data.
This new package comes with an interesting demo app, and it also feeds the updated SwiftUI + GRDB demo app.
Many thanks to @davedelong for the original inspiration (check out Core Data and SwiftUI | Dave DeLong), and @steipete for extra robustness!