Friday, June 26, 2015

Playground revisited for Xcode7

Yesterday I watched WWDC 2015 "What's new in Playground", snuggled down in my bed, ready to enjoy my session, better than a Luc Besson's movie ;)
(yes that's the kind of things geeks do).

I use playgrounds a lot.

They are part of my Swift toolbox. Good ideas found on Twitter, things I experiment, I store them in my Swift github repo. Very practical too, to share recipes with others.

If we look behind for a bit of history in playground releases (not to worry Playground and Swift are just one year old, so history will be short!).

Looking behind...

Xcode 6.0 beta brings playground. I'm convinced playgrounds have played a crucial role in the so rapid Swift adoption. Of course, playgrounds were quite buggy in beta and used to crash a lot but, with playgrounds, you can code Swift snippets, add text explanation to them to share with others. It's what the Swift guided tour offered you. You can even embed images ans CSS in Resources folder.

Xcode 6.2 brings us markdown format, see my blog post Even more fun with Playground. To me, this was one of the biggest improvement: not to have to write fragments of explantation in HTML and then associate Swift files using some XML glue file... Markdown is just great! See my Swift playground in Xcode6.2 format.

Xcode 6.3 brings us Sources folder. Like we used to have the Resources folder. So now to be able to test a Swift framework, you can put it in Sources. No need to work with a workspace like described in Playground and libraries post. We also have inline results, quite practical too. See my Swift playground in Xcode6.3 format.

So what's new in Xcode7?

Xcode 7 brings us Pages. I used to gather together all my Swift recipes in my toolbox within a workspace. With a workspace, I could also embed Swift library (prior to swift 6.3). But now with Xcode7, bye bye workspace, I'll stick to a single .playground file with different pages.

You can navigate between pages using markdown syntax:
[First Page](@first)
You can even go to one of your pages using its name. For a full markdown syntax go and visit Apple prerelease markdown reference page.

Enough talking, enough writing, let's convert my existing Swift toolbox into Swift2 and Xcode7 format. After trying the automatic Xcode Swift2 conversion (Go to: Edit -> Convert -> To Latest Swift Syntax), I gave up on that as it screwed up all my markdown and decided to migrate by hand. The code conversion was easy, the most tedious part was moving from .xcworkspace to one single .playground with multiple pages.

A few minutes later....
See my Swift playground in Xcode7 format.

Where's to go from here?

This year all WWDC videos are available to view to all developers, I encourage you to go through "What's new in Playground", a good video to enjoy with pop corn and coke.
Another great place to look at is Erica's blog, I haven't checked out her iBook on playground yet, I keep it for another great evening ;)

Last, do not forget to:
Practice, practice, practice.
Happy Swift2 playing!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.