Swift 3

The powerful programming language that is also easy to learn.

Swift is a powerful and intuitive programming language for macOS, iOS, watchOS and tvOS. Writing Swift code is interactive and fun, the syntax is concise yet expressive, and Swift includes modern features developers love. Swift code is safe by design, yet also produces software that runs lightning-fast.

Introducing Swift 3

Swift 3 is a thorough refinement of the language and the API conventions for the frameworks you use every day. These improvements make the code you write even more natural, while ensuring your code is much more consistent moving forward. For example, select Foundation types such as the new Date type are easier to use and are much faster than previous releases, and the Calendar type uses enums to feel more at home within Swift.

Learn Swift on iPad

Swift Playgrounds is a revolutionary new iPad app that helps you learn and explore coding in Swift. Built-in lessons and challenges teach fundamental coding concepts as you write real Swift code in an interactive environment designed for touch. You can follow through the included lessons, or create playgrounds to explore code at your own pace. And since Swift Playgrounds includes real iOS frameworks such as UIKit, SceneKit, and SpriteKit, and access to the hardware touch gestures, gyroscope, and camera, you can build nearly anything you can imagine.

Learn about Swift Playgrounds for iPad

Open Source

Swift 3 is the first major release developed in the open at Swift.org, with source code, a bug tracker, mailing lists, and regular development builds available for everyone. This broad community of developers, both inside Apple as well as hundreds of outside contributors, work together to make Swift even more amazing. Swift already supports all Apple platforms as well as Linux, with community members actively working to port to even more platforms. We're excited to see more ways in which Swift makes software safer and faster, while also making programming more fun.

To learn more about the open source Swift community, visit Swift.org

Refined API Naming

The syntax and patterns used in popular Swift libraries have almost as much impact on the character of Swift code as the specification of the language itself. This is why the Swift.org community drafted the Swift API Design Guidelines as part of the open source evolution process. These guidelines are applied throughout the standard library as well as throughout core frameworks such as Foundation, Core Graphics, and Grand Central Dispatch. Even frameworks originally written in Objective-C will feel dramatically more natural in Swift 3.

// old code (Swift 2.2)

let content = text.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet())

// new code (Swift 3.0)

let content2 = text.trimmingCharacters(in: .newlines)

Xcode 8 includes migration tools to help automatically move your Swift 2.2 code to the new Swift 3 syntax. If you are in the middle of a product release, you can keep using Swift 2 with Xcode 8 and still use the latest OS SDKs, then migrate your code to Swift 3 soon after. Swift 3 has the clear goal of setting up the language for source-level stability moving forward.


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. These forward-thinking concepts result 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

Playgrounds and REPL in Xcode

Much like Swift Playgrounds for iPad, playgrounds in Xcode make writing Swift code incredibly simple and fun. Type a line of code and the result appears immediately. You can then Quick Look the result from the side of your code, or pin that result directly below. The result view can display graphics, lists of results, or graphs of a value over time. You can open the Timeline Assistant to watch a complex view evolve and animate, great for experimenting with new UI code, or to play an animated SpriteKit scene as you code it. When you’ve perfected your code in the playground, simply move that code into your project.

Read-Eval-Print-Loop (REPL). The LLDB debugging console in Xcode includes an interactive version of the Swift language built right in. Use Swift syntax to evaluate and interact with your running app, or write new code to see how it works in a script-like environment. Available from within the Xcode console or in Terminal.

Fast and Powerful

From its earliest conception, Swift was built to be fast. Using the incredibly high-performance LLVM compiler, Swift code is transformed into optimized native code that gets the most out of modern hardware. The syntax and standard library have also been tuned to make the most obvious way to write your code also perform the best.

Swift is a successor to both the C and Objective-C languages. It includes low-level primitives such as types, flow control, and operators. It also provides object-oriented features such as classes, protocols, and generics, giving Cocoa and Cocoa Touch developers the performance and power they demand.

Designed for Safety

Swift eliminates entire classes of unsafe code. Variables are always initialized before use, arrays and integers are checked for overflow, and memory is managed automatically. Syntax is tuned to make it easy to define your intent — for example, simple three-character keywords define a variable ( var ) or constant ( let ).

Another safety feature is that by default Swift objects can never be nil. In fact, the Swift compiler will stop you from trying to make or use a nil object with a compile-time error. This makes writing code much cleaner and safer, and prevents a huge category of runtime crashes in your apps. However, there are cases where nil is valid and appropriate. For these situations Swift has an innovative feature known as optionals. An optional may contain nil, but Swift syntax forces you to safely deal with it using the ? syntax to indicate to the compiler you understand the behavior and will handle it safely.

Objective-C Interoperability

You can create an entirely new application with Swift today, or begin using Swift code to implement new features and functionality in your app. Swift code co-exists along side your existing Objective-C files in the same project, with full access to your Objective-C API, making it easy to adopt.

To get started with Swift, download Xcode and follow the tutorials available on the Resources tab.

Looking for the Swift parallel scripting language? Please visit swift-lang.org