I stumbled upon an API call without knowing it.
json-> swift type generation used quicktype
(Click here for the story of decoding failure when trying to get data from NewsAPI [Swift] A story that failed in decoding json acquired by News API and crushed it for half a day)
I had to use addingPercentEncoding when I wanted to fetch data from a URL containing Japanese in the API.
So in the case of URL including Japanese, it should have been written as follows
keyword
let NewsApiURL="https://newsapi.org/v2/everything?q=\(keyword)&num=3&sortBy=latest&apiKey=\(myApiKey)"
let encodedURL = NewsApiURL.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
guard let url = NSURL(string: encodedURL!) else {
print("Invalid URL.")
return
}
I gave it like this and it worked.
Recommended Posts