
上QQ阅读APP看书,第一时间看更新
How to add resource to a playground
Follow these steps to add an image to your playground. Try to use a .png or .jpg—images look great once you load them in a playground:
- Open the Navigator panel (cmd + 1)
- Select the Resources folder
- Press the + button at the bottom of the Navigator panel
- Select Add Files to 'Resources'...
- The file is automatically copied to the Resources folder
- Try to use it in the main playground
For example, to use an image in the iOS playground you can use the following code:
let img = UIImage(named: "open_xcode.png")
Where the name of the file is open_xcode.png. Don't worry about the code and what UIImage means. We will understand this a bit later on in the book. Take a look at the following screenshot:
Adding an image to your playground