Playground Secrets and Power Tips (v2) by Erica Sadun


  • Share on Pinterest

Note this review has been updated for the release of version 2.

I have been reading Playground Secrets and Power Tips by Erica Sadun, which you can purchase through the iBooks store (click the title to go directly to the book in the store).

BookCover

The book will teach you how to get the most from Xcode’s Swift playgrounds. I hope that all Swift developers are using them to test and develop code on the fly without creating unnecessary Xcode projects. While no previous knowledge is required, it is recommended that you at least have a working knowledge of the Swift language. The book covers version 1.2 using Xcode 6.3.

“Playgrounds aren't toys. They build real-world views, preview graphics, video, and audio using real-world Swift code.” – Erica Sadun

The beginning of the book covers the basics of explaining what a playground is and the interface elements with simple-to-follow examples helping you understand concepts like the timeline. These tips can be used in Xcode projects since they share the same editors. You will learn to quickly appreciate that a playground evaluates and executes code as you type. This can be immensely powerful for debugging and testing new ideas. Consider that you can develop and debug small chunks of code independent of an application or project, and quickly, you will develop things like classes with their test environment. There are also some handy time-saving tips for setting up keyboard shortcuts and behaviors.

Getting more in-depth, there are tips on using multiple source files, including the ability to have code in separate files (and resources) and use them in a playground, importing your Swift modules, visualizing data collections, and taking advantage of conditional compilation. For those unfamiliar with conditional compilation in code, it enables you to compile specific chunks of code based on the platform you are building, e.g., iOS or OS X.

One handy tip you may not have considered is using Xcode-style bookmarks in playgrounds. It is easy to think of playgrounds as small test files and forget that you can build complete applications and test them if you wish. Such extended source code always benefits from documentation and bookmarks for fast navigation. Indeed, there is a chapter on documentation with rich examples.

Swift 2 playgrounds support the use of multi-page playgrounds. Erica does a great job of walking you through this feature, along with a superb section explaining the use of rich comments using a variation of markdown that can be used to turn playgrounds into interactive workbooks.

Chapter 6 will take you deep into the .playground bundle, explaining how it works and how you can use it to your advantage to create your own Xcode templates. I admit this chapter was over my head the first couple of times, but after a while, it started to make sense.

For those who build OS X applications, chapter 7 has some helpful tips and guides for working in playgrounds, including with NIBs and Windows.

The wrap-up & conclusion

To wrap up this mini-review, I can recommend this book to Swift developers of any level who want to get more from playgrounds, be it development, testing, or just for fun exploration. Remember that you need to use Swift 1.2 and Xcode 6.3 to get the most out of it, with some features only available in the (Currently Beta, final release in the Fall of 2015) Xcode 7 and Swift 2.

Here is a link to the book in the iBook store, and I also recommend following Erica on Twitter @ericasadun

All excerpts and cover images are copyrighted by Erica Sadun.

Reviews of other books in Erica's collection

Swift Documentation Markup by Erica Sadun

Swift Style by Erica Sadun

  • Adam
    Author
    Adam Adam

    Thanks for reviewing this book. I have been on the fence about getting it and your review convinced me to pick it up. Thanks – Adam

    • Peter Witham
      Author
      Peter Witham Peter Witham

      You are most welcome Adam, the book taught me things that would of taken me a while to stumble across.

      Thanks,
      Peter.