Skip to content

Defining a @Query with a variable #29

Answered by groue
foodstan asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @foodstan,

Check the "Configuring the Initial Request" section of Adding Parameters to Queryable Types, and the following sections.

In your case, since MainView just wants to initialize MessageList with an "initial request", you'll probably end up with:

struct MessageList: View {
    @Query<MessageRequest> private var messages: [Message]

    init(group: Group) {
        let request = MessageRequest(group: group)
        _messages = Query(request)
    }
}

This will allow MessageList to further control the request if it needs (filter messages, etc), through $messages.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@foodstan
Comment options

Answer selected by foodstan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants