Wednesday, July 9, 2014

Switch to Swift

June 2nd 2014 at WWDC, Apple gave birth to Swift: a brand new language for developing iOS and Mac apps! Much ink has been spilled since then, comparing Swift to other languages. And yes, there is some family resemblance. Some see it as a disadvantage, see Ash furrow blog post, but to me, it has advantages: bring all the good stuff together :)

REPL && Playground

From Apple: "Xcode’s debugger includes an interactive version of the Swift language, known as the REPL (Read-Eval-Print-Loop). Use Swift syntax to evaluate and interact with your running app or write new code in a script-like environment. The REPL is available from within LLDB in Xcode’s console, or from Terminal."

So you can use Swift in your terminal! Very convenient to try this out, get your hands into Swift.

> sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer
> xcrun swift

And even better, you can run in your debugger.

But what I like best is Playground. What an amazing feature being able to type a line of code and see the result immediately. Having a script like experience with a compiled language. Not a new idea, Scala had his worksheet, but what I really like with Playground is that you can also play with graphical object. Apple released a complete Swift book and a Guided tour playground where you can play with the language as you learn it. Pretty neat!

At the time of writing, with XcodeBeta2 there is still bugs and I manage to get it crashed a dozen of time today. But no doubt it will improve.

Objective-C / Swift interoperability

From the start, Swift was designed to work with Objective-C. From Apple Inc. “The Swift Programming Language.” iBooks:
“ [Swift] provides seamless access to existing Cocoa frameworks and mix-and-match interoperability with Objective-C code. ”

There is also a whole iBook dedicated to compatibility matters, "Using Swift with coco and Objective-C". If you're part of apple iOS developer program, the videos to watch on compatibility matter are session 406 "Integrating Swift with Objective-C" and session 407 "Swift interoperability in Depth".

Stay tuned, I will write more on the topic really soon with short examples on playground off course ;)

First impressions

Swift is here to stay, that's for sure. It's already broadly used. Github will tell you.
Benchmark are not so good so far but no doubt things will improve.

Ready to switch to Swift?

At AeroGear, we're on the starting block, getting ready for iOS8 official announcement. Don't want to unveil too soon, but our 2.0 release is going to be Swifty... No Apple way here, we're open! If you want to know more, read the mailing list aerogear-dev@lists.jboss.org and send your feedback!

No comments:

Post a Comment

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