That high-level road map and a few details about the syntax of declaring variables is all you need to get going. Within a few days of Apple's announcement, open source software written in Swift started appearing on GitHub. One of the most impressive, a clone of Flappy Birds by Nate Murray, required just two major Swift files and a bit of glue code. If you know your way around OS X or iOS programming, you can get moving very quickly. Murray says he spent only a day on his clone.
Swift fixes a few of the biggest complaints about Java syntax. You won't need to waste keystrokes spelling out the type of each variable; the compiler will infer it from initialization. You get all of the advantages of letting the compiler check the types without many of the keystrokes. If you want to glue together variables and strings, a simple templating hack uses a mere three keystrokes to insert a variable into a string. It's a masterstroke.
For all of the advances and improvements, I found the size of Swift to be a bit daunting. While it's easy to see how Nate Murray knocked off Flappy Birds in a day, many other details of the language can't be mastered in a few minutes. I spent some time puzzling about the difference between data that's passed around by value (
struct) and data that's passed around by pointers (
class). Juggling these differences is one of the big challenges to C programming, and it will remain an issue for Swift programmers who want to squeeze the best performance out of their code.
Optimization will probably be a real headache for some kinds of code. Strings, for instance, are always passed by value, which means Swift will be making copies of strings left and right with every function call. This may not be much of an issue for graphics-based programs like games, but programs like Web servers and content management systems are essentially concatenation machines. Anyone who starts juggling strings will need to pay attention to this when writing Swift code. They may end up wrapping the string values in classes to avoid the copying.
There are a number of other areas that I earmarked for deeper study. Downcasting, for instance, lets you shift the focus from a class to a subclass with the typecasting operator (
as). This may fail, so there's another typecasting operator with a question mark (
as?), which returns the value of
nil if the downcast doesn't succeed. There are a number of these optional features where the presence or absence of the question mark changes the behavior of keywords. Another feature, subscripts, lets you dig into a class quickly to pull out a particular value. It's neat shorthand, but it has the potential to confuse.
Having trouble installing and setting up Win10? You aren’t alone. Here are many of the most common...
It's all about knowing how to build an open source community -- plus experience running applications in...
Win7 Update scans got you fuming? Here’s how to make the most of Microsoft’s 'magic' speed-up patch
The proliferation of insecure devices in every facet of our lives will have consequences far beyond the...
From a simple platform for beginners to an expert-level development workbench, there's an IDE for most...
You don't need to buy a new phone to add hours to your battery. All you need is to flip a few switches...
Look to these clever open source tools to keep secrets out of source code, identify malicious files,...