The basic structure of Swift is similar to Java. The entire code is divided into classes which comprises of fields and methods. What sets it apart from Java is the declaration of the syntax and other simplified features. For example a function declaration starts with a keyword (func) and return value comes after the method name, not before it, unlike Java. The WWDC app is the first publicly released app written in Swift. Apple introduced version 1.0 of Swift with the Golden Master of Xcode 6.0 for iOS in September 2014. Apple isn’t killing Objective-C, it will stay along with Swift. Many old developers will stick to Objective-C rather than learning an entirely new language to do the same thing that they already know how to. Swift is aimed at attracting newcomers.
Apple highlighting the important features of Swift at WWDC 14
Apple calls it “Objective-C without the C”. It is simpler and easier to use than Objective-C. A new programming language takes years to develop a large community and that’s no secret. Swift, however, has a different story here. Because of its simplicity and the ever growing ranks of iOS and OS X developers it could achieve mass adoption with an unprecedented speed. Swift is expected to surpass the uptake of Sun Microsystems’ Java programming language and Microsoft’s C# in the late 1990s and early 2000s. Swift isn’t as attractive as the popular programming languages out there like Ruby, Python and C#. Its only advantage is its simplicity over Objective-C which uses the complex mid-80s style, which is not easy to use as modern programming languages. Swift brings a new tool called “Playground”, which lets you see the program as you write enabling you to teach yourself to code. With Swift you won’t need to waste time and keystrokes mentioning the type of each variable; the compiler will infer it from initialization.
Using Playground to see the code results then and there.
In addition to this there are some interesting and unusual features like:-
Multiple return values - Swift allows multiple return values for a function. Looking at it in another way, it returns only single value which is a tuple that can be changed during the runtime.
Generics - Like Java, Swift also supports generic classes and functions.
Class like Structures - Swift supports structures as well as classes in the same manner as Objective-C. However, one way Swift stands apart is by providing support for functions in structures.
Trailing Closures - A new feature that adds closures at the end of the code which arranges it in a more natural way.
Operator Overloading - In addition to the predefined operators, Swift lets you overload entirely new characters from a limited character set.
Among the popular Swift libraries or repositories on GitHub are:
Swiftz - For functional programming that defines purely functional data structures and functions. Download it here
ReactKit - For reactive programming in Swift. Download it here
Alamofire - For elegant HTTP networking in Swift. Download it here
Animated tab bar - Animated Tab Bar is a Swift module for animating tab bar elements. Download it here
Quick - The Swift testing framework. Download it here
FlappySwift - Implementation of Flappy Bird in Swift. Download it here
Swifter - A Twitter framework for iOS and OS X written in Swift. Download it here
Chats - An open source native iPhone messaging app. Download it here
SwiftWeather - A weather app for iOS developed in Swift. Download it here
In comparison to other programming languages there are very few libraries available for Swift. This newly released language needs more developers to match up to other popular languages.
Libraries and frameworks creating reusable code.
Tools and Resources
Apple’s new language lies within Apple’s ecosystem. Development for Apple products always happens in Apple’s environment, Swift is no exception. To develop in Swift you need a Mac based computer running OS X Yosemite. Like Objective-C, the development in Swift happens using Xcode IDE. Apple announced Xcode 6 this year with Swift support. Unlike other programming languages, there is no alternative IDE available at the moment. If you have a Mac, you can go to the App Store and download Xcode 6 for free. The newly introduced language has a plethora of learning resources available. Many websites offer free as well as paid resources that include tutorials and articles. Additionally, StackOverflow is also flooded with queries related to Swift.
Apple has published “The Swift Language Reference” ebook on the iTunes Store for free. Alternatively, you can get your hands on the same ebook in HTML format on Apple’s website.
SoSoSwift is a great website dedicated for Swift language. It’s an index consisting of Swift tutorials sourced from all over the Internet.
Bloc offers free tutorials which will guide you in building your very first 2D game in Swift using Spire kit.
LearnSwift consists of a curated list of helpful resources to learn Swift, which includes tutorials, code samples, code libraries and references.
Using Xcode 6 to develop an iOS app with Swift language.
Ray Wenderlich is a popular website that offers iOS development tutorials. With the launch of the new language, the website has updated its database with tutorials that cover the basics of the language as well as simple apps written in Swift using several iOS frameworks.
Objective-C classes in Swift
If you are interested in using the old Objective-C classes in Swift this is a neat step by step guide for creating a bridging header.
Higher Order Functions in Swift
Learn everything about closures in Swift and how they can be used to build filters, maps, and reduce sequence operations here.