Now I'm using UIImage sync extension.
struct PostView: View {
let url: String
var body: some View {
PrivateImageView(image: UIImage(url:url))
}
}
extension UIImage {
public convenience init(url: String) {
let url = URL(string: url)
do {
let data = try Data(contentsOf: url!)
self.init(data: data)!
return
} catch let err {
print("Error : \(err.localizedDescription)")
}
self.init()
}
}
When I post a image, I got the error Synchronous URL loading of http://local.host/images/123.jpeg should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.
at try Data(contentsOf: url!)
.
In PostView I use PrivateImageView
.
To use the view I have to designate the argument like this PrivateImageView(image: UIImage(xxxxxxxxx))
.
I mean I have to use UIImage()
not AsyncImage
.
I don't know how to change convenience init
to adjust to PrivateImageView
.
Please tell me how to use an async function in this context.