How can I use image inside Xcode 11 playground?

Viewed 2046

I am doing the SwiftUI tutorial which is on the Apple's website in Xcode 11 playground because I use Mojave and not Catalina. There is an image called turtlerock.jpg, but it doesn't show in the playground.

I put the image inside the resource folder, but no luck.

1 Answers

I've been scratching my head over this problem too. I've managed to find at least a workaround for now:

Instead of:

Image("turtlerock")

try:

Image(uiImage: UIImage(named: "turtlerock.jpg")!)

You'll have to have turtlerock.jpg in the Resources folder of your playground. If you turn it into a .png first, you can use UIImage(named: "turtlerock") in the above.

Related