You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GRDBQuery helps SwiftUI applications access a local SQLite database through GRDB and the SwiftUI environment.
It comes in two flavors:
The @Query property wrapper allows SwiftUI views to directly read and observe the database:
/// Displays an always up-to-date list of database players.
structPlayerList:View{@Query(PlayersRequest())varplayers:[Player]varbody:someView{List(players){ player inText(player.name)}}}
The @EnvironmentStateObject property wrapper helps building ObservableObject models from the SwiftUI environment:
/// Displays an always up-to-date list of database players.
structPlayerList:View{@EnvironmentStateObjectvarmodel:PlayerListModel=[]init(){
_model =EnvironmentStateObject{ env inPlayerListModel(databaseContext: env.databaseContext)}}varbody:someView{List(model.players){ player inText(player.name)}}}
Both techniques can be used in a single application, so that developers can run quick experiments, build versatile previews, and also apply strict patterns and conventions. Pick @Query, or @EnvironmentStateObject, depending on your needs!
Documentation
Learn how to use @Query and @EnvironmentStateObject in the Documentation.