Skip to content

Self-closing tag #272

Closed Answered by soundbanana
soundbanana asked this question in Q&A
May 7, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote
func predict(searchText: String) async {
        let encodedTexts = searchText.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)

        guard let url = URL(string: "https://suggestqueries.google.com/complete/search?ds=yt&output=xml&q=\(encodedTexts!)") else {
            return }

        do {
            let (data, _) = try await session.data(from: url)
            let xml = XMLHash.parse(data)

            let predictons = xml["toplevel"]["CompleteSuggestion"].all.map { elem in
                elem["suggestion"].element?.attribute(by: "data")?.text
            }
            predictionsList = predictons.compactMap { $0 }
        } catch {
            print(er…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by soundbanana
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