Thursday, August 28, 2014

Playground has never been so fun

Since Xcode6 beta first launch in June 2014 at WWDC, its most popular and fun feature has always been Playground - or at least for me :]
Imagine the fun to be able to run code snippets, have them executed in a glimpse and all that for a type safe compiled language like Swift. This sounds like the panacea of quick prototyping and Nirvarna to Swift newbies.

Off course, along the beta path, I learned the few caveats and things you can't do with Playgrounds. There are a few issues and limitations. Crashing Xcode betaX is more likely with Playgrounds. Some weird issues like string interpolation not working in Playground, or difficult stuff like how to do asynchronous call etc... But my enthusiast toward Playground is still intact.

Since I read in Swift forum (a great place to learn btw), with Xcode6 beta 5, it is possible to import your own library within a playground sheet. All you need to do is have them (framework and playground) bundled together in a workspace. How cool!

I've tested it on aerogear-ios-http, see the PR here. All you need to do:

Step 1. Create an iOS Framework & library project... or use an existing one

Step 2. Save as workspace

Step 3. Add playground file

Step 4. Build and run test for your framework using 64bits simulator (iPhone5S)

Step 5. import your module in playground and demo your API usage


I found this is ideal to quickly show case how to use a library et let the developer plays with it.

Happy Swifting!

1 comment:

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