Note: this is asked because I am not sure if the code I wrote remains working in the future from this PR: https://github.com/groue/GRDBQuery/pull/7
In library GRDBQuery, there is a propertyWrapper @Query
. That property wrapper will update values if they are changed in the database. The Query
wrapper is automatically initialized with a database provided from the Environment of SwiftUI.
If you put things in your Environment, it means it needs to have a default value, e.g.: GRDBQuery/QueryDemoApp.swift at 5e36db6148ac24f8cbfba8ed1aa27547259b2137 · groue/GRDBQuery · GitHub. This creates an empty database, just because Environment requires it, I don't want it.
Furthermore, I want to use the Query
wrapper with more parameters, I am not sure how I can do that without explicitly initializing it. The values I want to use are available when initializing the View, so I was hoping I could just explicitly initializing Query
with those values. This is how I currently do it:
@Query<Player> var players: [Player]
init(database: DatabaseQueue) {
_players = .init(
request: AllPlayers(),
database: database
)
}
This uses a private api I guess, because I need to assign players to an underscore variant. I was wondering: is there a 'better' way of initializing a property wrapper explicitly? Is this legal? I can now pass in custom values in my View through the init
block and directly pass those to the Query
wrapper, exactly how I want it, but it uses this weird underscore, which I don't feel comfortable using.