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 needed 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 this book's GitHub repository at https://github.com/PacktPublishing/Swift-Cookbook-Second-Edition/tree/master/Chapter07/02_Import_Resources_into_Playgrounds.
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...