Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Created August 7, 2019 22:56
Show Gist options
  • Select an option

  • Save PaulWoodIII/61c9be0dac47499f310e9eebbbe7250c to your computer and use it in GitHub Desktop.

Select an option

Save PaulWoodIII/61c9be0dac47499f310e9eebbbe7250c to your computer and use it in GitHub Desktop.
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
struct ExampleView: View {
@ObservedObject var fetcher: ImageFetcher
init(fetcher: ImageFetcher) {
self.fetcher = fetcher
}
var body: some View {
VStack {
if fetcher.image != nil {
Image(uiImage: fetcher.image!)
.resizable()
.aspectRatio(contentMode: .fit)
}
else {
EmptyView()
}
}
.onAppear(perform: fetcher.refresh)
}
}
let viewController = UIHostingController(rootView:
ExampleView(fetcher: ImageFetcher(url: URL(string: "https://avatars3.githubusercontent.com/u/949286?s=400&v=4")!))
)
PlaygroundPage.current.liveView = viewController
//: [Next](@next)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment