Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use image inside Xcode 11 playground?

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.

like image 735
Maric Vikike Avatar asked Jun 09 '19 10:06

Maric Vikike


People also ask

How to create playground project in Xcode?

1. How To Create Playground Project Use Xcode. When you start Xcode, there are three project templates that you can choose to create, click the first item Get started with a playground to create a playground project.

How to create a new playground in Windows 10?

In the earlier versions in the first option, we would see the “Create a new Playground” option. But here we need to put a small extra effort to get that option. First, click on File as shown in the below image. After clicking on File you will have to hover your cursor on New and then simply click on Playground.

How do I render a poem in Xcode?

To show it in its rendered form, select the button in the top right corner of the window, which shows Xcode's Inspector. Then select Render Documentation under Playground Settings. The lines in my poem are now rendered. Other interesting things you can do with the markup are adding headings to a Playground peach.

What is playground description in iOS 14?

Playground Description is of type Any, which means you can return anything that you feel best describes your value. Now, there are certain types that have specialized representations already and those are provided by Apple.


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.

like image 152
David Ackerman Avatar answered Sep 30 '22 17:09

David Ackerman