I tried running your code sample in Swift.
I keep getting the following error via Xcode:
“A server with the specified hostname could not be found.”
Here’s my code:
func fetchData() async throws -> [Location] {
let url = URL(string: “https://zillow-base1.p.rapidapi.com/WebAPIs/zillow/locationSuggestions/v2?location=Brownsville%2C TX”)!
let headers = [
“X-RapidAPI-Key”: “1f7f2f561emsh5142da984f24635p19dcccjsn034500ecc809”,
“X-RapidAPI-Host”: “zillow-base1.p.rapidapi.com”
]
var request = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let (data, _) = try await URLSession.shared.data(for: request)
let decoder = JSONDecoder()
let locations = try decoder.decode([Location].self, from: data)
return locations
}
चर्चा में शामिल हों - नीचे टिप्पणी जोड़ें:
Hi amourinetech,
I’m sorry for the delayed response.
Regarding the code you provided, I don’t have a MAC machine here, so I haven’t been able to test that piece of code yet.
I hope you understand.