'(SwiftUI) How to search using IGDB api, search in api

I need help I have app I'm using IGDB api and displaying games with no issue. I need ability to make user search and send the user text to api to display the game from API. here is my

class GameStore: GameService {
    @Published var searchText: String = ""

    func searchGame(searchText: String, for platform: Platform, completion: @escaping (Result<[Game], Error>) -> Void) {
        print("Time is: ",timeStamp)
        wrapper.apiProtoRequest(
            endpoint: .GAMES,
            apicalypseQuery: "fields name, summary, first_release_date, id, rating, involved_companies.company.name, cover.image_id, game_modes.name, platforms.name, screenshots.image_id, platforms.platform_logo.image_id, websites.url, genres.name, themes.name; where (platforms = (49,130,48,6) & first_release_date > \(timeStamp)); search \(searchText); limit 100;",
            dataResponse: { bytes in
                guard let gameResults = try? Proto_GameResult(serializedData: bytes) else {
                    return
                }
                let games = gameResults.games.map { Game(game: $0) }
                DispatchQueue.main.async {
                    completion(.success(games))
                }
            }, errorResponse: { error in
                DispatchQueue.main.async {
                    completion(.failure(error))
                }
            })
    }
}

here is the query for search function I need to pass the data from Game view using search bar and send the user text to this query

here is my code for Game list view

VStack {
    TextField("Search Games", text: $search)
        .textFieldStyle(RoundedBorderTextFieldStyle())
        .padding()

    if search.isEmpty {
        if #available(iOS 15.0, *) {
            LazyVGrid(columns: columns, spacing: 20) {
                ForEach(self.gameList.games) { (game: Game) in
                    NavigationLink(destination: GameDetailView(gameId: game.id)) {
                        GameRowView(game: game)
                    }
                }
            }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source