A month ago, I was sitting in Moscone West, watching Craig Federighi presenting on stage. “This release is the biggest release since the launch of the App Store.” when Craig said that, I was wondering if there would be a new device or not, but Francis who was sitting next to me got a much better guess, “Maybe a new language?”
It has been two months after Apple announced Swift, their new programming language. To get a taste of it, I have rewritten one of my apps, Hong Kong Ferries Timetable using Swift and opensourced it. Keep in mind that Swift is still in beta, everything could change.
One of the biggest feature of Swift is heavily typed, and
doesnt?exist ?? default
self. improved readability
override keyword when overriding super class is nice
required keyword, it can be kind of redundant
var array:Array =  is mutable
let array:Array =  is not
let array:NSMutableArray =  is mutable
There is @NSManaged, but that is only for CoreData So you cannot extend CALayer to animate custom properties
Some specific functions only work if you use the @objc attribute, but the tradeoff are Swift-only functions. For example you will need @objc to check for protocol conformance
You can check for protocol conformance only if your protocol is marked with the @objc attribute
And also @optional
Optional protocol requirements can only be specified if your protocol is marked with the @objc attribute. Even if you are not interoperating with Objective-C, you need to mark your protocols with the @objc attribute if you want to specify optional requirements.
More to go.
Maybe you will need to think twice before designing API, you couldn’t use some nice feature like enum with raw values.
Playground is a really nice way to try out Swift. And it helps me to debug graphic-drawing code as well. With playground, I can debug code in
drawRect: easily, seeing them draw step by step. However playground is still not stable.
#Xcode Xcode is not ready yet, at least for now
When Swift is announced, Apple did not only prepared a full documentation, they also wrote a book to explain everything very well. When you browse Objective-C headers in Xcode, it even create a Swift version so you can copy method names easily. Although the community is still young, there are a number of StackOver posts that would guide you through problems.
##Not that great for beginners
If you understand Objective-C, you have much greater chance to find a solution than Swift’s. Afterall, you have to understand Objective-C to fully leverage the platform. Just like even thought there is ARC to help you to manage memory, you will have to understand what is retain and release, instead of writting
Article Image from http://www.flickr.com/photos/lipkee/4916308411/in/photostream/