Swift playgrounds with UIImage

Ross Gibson picture Ross Gibson · Jun 5, 2014 · Viewed 58.8k times · Source

I am working with Xcode 6, and I'm trying to recreate the code demoed during session 401 "What's new in Xcode 6". I've added an image to Images.xcassets (called Sample) and within the playground file I'm trying to access this image, as demoed.

My code is as follows (like the demo):

var sample = UIImage(named: "Sample")

However, I can't get it to work like the demo. Am I missing something?

Answer

Bruce picture Bruce · Jun 11, 2015

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