Alex Bollbach
Alex Bollbach

Reputation: 4600

How to load an image into an Xcode 9 playground?

I've spent hours trying to simply gain access to image data in my Swift Playground. I've followed many tutorials that recommend adding a resource folder as a sibling dir in the dir. your playground is in. Or to drag images into the Resources folder in the playground Navigator. Nothing has worked. What do I have to do to load an image view in playground?

Upvotes: 4

Views: 5343

Answers (1)

SchmidtFx
SchmidtFx

Reputation: 626

I solved this problem on my side when I

  1. import PlaygroundSupport
  2. mark Resources Folder and tap + icon
  3. Choose Add files to 'Resources' and choose your image (here: image.jpg)
  4. Instance your image via let image = UIImage(named: "image.jpg")

Xcode 12 Preview

enter image description here

Upvotes: 10

Related Questions