0

How do we display an image in a SwiftUI playground? I put a png file in the Resources folder called "test.png" and this is my code and it displays a blank white screen. I tried putting an xcassets file containing the image into Resources and still I get a blank white screen. What do I need to do?

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        Image("test")
    }
}

PlaygroundPage.current.setLiveView(ContentView())
s519
  • 1
  • check [this](https://stackoverflow.com/a/24109505/5941807) – Joannes Sep 12 '20 at 11:11
  • Joannes, thanks but that does not help. That post is out-dated and I've already tried everything relevant from that thread. – s519 Sep 13 '20 at 10:05
  • This question is really specific to SwiftUI, I don't have a problem displaying the image using UIKIt. – s519 Sep 13 '20 at 10:11

1 Answers1

0

Using the Image(uiImage: UIImage)

Click the + sign and select Insert image from... or Photos

after clicking +

code

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")
            Image(uiImage: #imageLiteral(resourceName: "imagetitle.jpg"))
        }
    }
}

PlaygroundPage.current.setLiveView(ContentView())