Import Code into Playgrounds
As we have seen throughout this chapter, and this book, playgrounds are a great canvas for exploring APIs, frameworks, and custom code. However, if you want to explore uses for your own code, it appears that you need to include all the code in the playground and that can make it long and unwieldy.
It doesn't need to be that way. In this recipe, we will see how you can embed Swift code in your playground and make use of it from your playground code.
Getting ready
For this recipe, we will use the playground from the previous recipe, called EmbeddedResources.playground
, which can be retrieved from the GitHub repository for this chapter at http://swiftbook.link/code/chapter6.
How to do it...
We will take the BarChart
custom view and related code, and move it to a separate file embedded within the playground, leaving us free to use the playground to experiment with our custom view. Let's look at these steps:
- If the playground's project navigator isn't visible, select
View...