Apple Swift Logo

Swift. A powerful open language that lets everyone build amazing apps.

Swift is a robust and intuitive programming language created by Apple for building apps for iOS, Mac, Apple TV, and Apple Watch. It’s designed to give developers more freedom than ever. Swift is easy to use and open source, so anyone with an idea can create something incredible.

Swift has been refined from the ground up. It generates faster code across the board, both for release and debug builds. The Swift compiler is also faster, even while adding new Fix-it suggestions such as where you can use let instead of var. Comments can include Markdown syntax to add rich text and embedded images that display in Xcode’s Quick Help. A new assistant shows your Swift API in a “header-like” view. And new syntax features combined with improvements to the Cocoa frameworks and Objective-C will make your code more expressive, and even safer.

Syntax improvements

New syntax features let you write more expressive code while improving consistency across the language. The SDKs have employed new Objective-C features such as generics and nullability annotation to make Swift code even cleaner and safer. Here is just a sampling of Swift 2.0 enhancements.

  • Powerful control flow with do, guard, defer, and repeat
  • Keyword naming rules unified for functions and methods
  • Protocol extensions and default implementations
  • Extended pattern matching to work in if clauses and for loops

Xcode 7 includes a powerful migrator that will help convert your application and playground code to work with the latest syntax improvements in Swift 2.0.

Error handling model

An advanced error handling model provides clear, expressive syntax for catching and throwing errors. It’s also easy to create your own custom error types so you can describe error cases with clear, meaningful names. The new error model was designed to work seamlessly with NSError and the Cocoa frameworks. Error handling code now looks like:

func loadData() throws { }

func test() {
	do {
		try loadData()
	} catch {
		print(error)
	}

Availability

You should always use the latest SDK to get access to the latest features, documentation, and API changes, but sometimes your app needs to run on an older OS. Swift 2.0 has built-in availability checking to make it easy to build the best possible app for each target OS version. The compiler will give you an error when using an API too new for your minimum target OS, and a new keyword lets you wrap blocks of code in a conditional version check to run only on specific OS releases.

Modern

Swift is the result of the latest research on programming languages, combined with decades of experience building Apple platforms. Named parameters brought forward from Objective-C are expressed in a clean syntax that makes APIs in Swift even easier to read and maintain. Inferred types make code cleaner and less prone to mistakes, while modules eliminate headers and provide namespaces. Memory is managed automatically, and you don’t even need to type semi-colons. All this modern thinking results in a language that is easy and fun to use.

extension String {
    var banana : String {
    	let shortName = String(characters.dropFirst(1))
    	return "\(self) \(self) Bo B\(shortName) Banana Fana Fo F\(shortName)"
	}
}

let bananaName = "Jimmy".banana		// "Jimmy Jimmy Bo Bimmy Banana Fana Fo Fimmy"

Swift has many other features to make your code more expressive:

  • Closures unified with function pointers
  • Tuples and multiple return values
  • Generics
  • Fast and concise iteration over a range or collection
  • Structs that support methods, extensions, and protocols
  • Functional programming patterns, e.g., map and filter
  • Native error handling using try / catch / throw

Now is avaliable for linux.

Specifically, Swift 2.2 includes support for Swift on Ubuntu Linux 14.04 and 15.10. Apple admits that "The Linux port is still relatively new and in this release does not include the Swift Core Libraries (which will appear in Swift 3). The port does, however, include LLDB, a debugger, and the REPL [Read Eval Print Loop]."

Otherwise, this is a relatively minor release. Still, this "release includes contributions from 212 non-Apple contributors -- changes that span from simple bug fixes to enhancements and alterations to the core language and Swift Standard Library."

Maybe Apple is starting to get the open-source religion as well. After all, if Microsoft can convert, why not Apple?
Download Swift2 for linux    
More info about Swift2