You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Foundation
leturl=URL(string:"http://example.com/image.png")!
varrequest=URLRequest(url: url)lettask=URLSession.shared.dataTask(with: request){(data, response, error)in
if let error = error {print(error)}else if let data = data {letstr=String(data: data, encoding:.utf8)print(str ??"")}}
task.resume()
In this code, received data is converted to UTF-8, which is only desirable if UTF-8 encoded text data is fetched. This is not always the case -- fetching binary data like images and also text data in different encodings (especially HTML with correctly set encoding) is quite common. Also, no UTF-8 conversion is done in most other examples, so if probably shouldn't be a thing in Swift either.
Possibly, a similar problem lies with Kotlin, which converts the response body to a string:
Swift generator currently produces this code:
In this code, received data is converted to UTF-8, which is only desirable if UTF-8 encoded text data is fetched. This is not always the case -- fetching binary data like images and also text data in different encodings (especially HTML with correctly set encoding) is quite common. Also, no UTF-8 conversion is done in most other examples, so if probably shouldn't be a thing in Swift either.
Possibly, a similar problem lies with Kotlin, which converts the response body to a string:
The text was updated successfully, but these errors were encountered: