I have an app made in Swift/SwiftUI with Xcode 14.2(if that matters).
I have a search field which when changed runs a search() function which parses text and makes an HTTP query. There is some sort of a problem with the way I'm parsing the query (i think) and the app crashes when cyrillic text and emojis are entered (a.k.a. anything that's not plain english).
This is the code I currently have in the app:
func search(query: String) async throws {
let requestURL = "https://myapilink/api/find?q=\(query)&apikey=areallylongapikey"
let newRequestURL = requestURL.replacingOccurrences(of: " ", with: "%20")
var request = URLRequest(url: URL(string: newRequestURL)!)
let (data, _) = try await URLSession.shared.data(for: request)
let searchResponse = try JSONDecoder().decode(SearchResponse.self, from: data)
lists = searchResponse.lists
}
Any help would be appreciated.
Firstly, I was experiencing issues when even entering spaces. I quickly realised that was because the URL expects spaces to be parsed with "%20" - the space symbol equivalent for URLs. I fixed the issue, but later on found another one.