Swift playgrounds with UIImage Swift playgrounds with UIImage ios ios

Swift playgrounds with UIImage


Look at the iOS Developer Library->Playground Help and search"Resource Files" and you will find the answer

1、Open the .playground

2、Show the Project navigator by selecting View > Navigators > Show Project Navigator.

3、Drag the images to the Resources

Like follow:

enter image description here


  1. Open the .playground file in Finder.
  2. Create a folder called Resources next to it.
  3. Add any images you want to this folder.
  4. In the playground press opt-cmd-1 to open the File Inspector. You should see the playground on the right. If you don't have it selected, press cmd-1 to open the Project Navigator and click on the playground file.

File Inspector

  1. Under 'Resource Path' choose 'Relative To Playground'
  2. Click the folder icon underneath and choose the Resources folder created earlier.

You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):

Working nsbundle image

Note: Because Xcode will frequently overwrite the .playground folder, I recommend using this method so the resources folder isn't getting constantly deleted and re-created.


I had some trouble with this also.

Unfortunately, Chris' answer didn't work for me. I suspect perhaps a later beta release of Xcode 6 may have removed this setting.

Here's a solution as of Xcode 6.0 beta 4 (6A267N) available 21st July 2014. I would guess that this corresponds to the "Inside playground" option previously. That is where the Resources folder is within the playground package itself.

Here's how to set this up.

Using Finder - or if you're like me and use the awesome Path Finder - right select and choose Show Package Contents as follows:

enter image description here

That reveals the packages Resources folder:

enter image description here

Copying the image files into that folder will do the business:

let imageNames = ["back-button", "background", "bg_top"]let images = imageNames.map { UIImage(named: $0) }

enter image description here