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?
Learning to code with Swift Playgrounds is incredibly engaging. The app comes with a complete set of Apple-designed lessons. Play your way through the basics in “Get Started with Code” using real code to guide a character through a 3D world. Then move on to more advanced concepts.
Simply put, after about an hour, even grown adults should be fully engaged by Swift Playgrounds' playful coding puzzles. That's a big win. Parents and children can go through these activities together, and they can both really get something out of it.
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:
You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With