// // LoadableImageView.swift // tst // // Created by Vitaly Takmazov on 10.12.2019. // Copyright © 2019 com.juick. All rights reserved. // import SwiftUI struct LoadableImageView: View { @ObservedObject var imageFetcher: ImageFetcher init(with urlString: String) { imageFetcher = ImageFetcher(url: urlString) } var body: some View { if let image = UIImage(data: imageFetcher.data) { return AnyView( Image(uiImage: image).resizable() ) } else { return AnyView( ActivityIndicator(style: .medium) ) } } } struct LoadableImageView_Previews: PreviewProvider { static var previews: some View { LoadableImageView(with: "https://i.juick.com/a/1.png") } }