Swift

Swift is a powerful and intuitive programming language for all Apple platforms. It's easy to get started using Swift, with a concise-yet-expressive syntax and modern features you'll love. Swift code is safe by design and produces software that runs lightning fast.

Get to know Swift

Expressive

With an expressive, easy-to-read syntax, Swift empowers new developers to quickly understand core programming concepts. And with resources like the Develop in Swift Tutorials, Swift Coding Clubs, and Swift Playground, it's never been easier to get started with Swift as your first programming language.

Learn more about Swift education resources from Apple


Experienced developers can also quickly dive in and take advantage of the power and safety of Swift, with the comfort of familiar modern features used in other programming languages.

struct Player {
	var name: String
	var highScore: Int = 0
	var history: [Int] = []
	
	init(_ name: String) {
		self.name = name
		}
}

var player = Player("Tomas")

Declare new types with modern, straightforward syntax, provide default values for instance properties, and define custom initializers.

extension Player {
mutating func updateScore(_ newScore: Int) {
	history.append(newScore)
	if highScore < newScore {
		print("\(newScore)! A new high score for \(name)! 🎉")
		highScore = newScore
	}
}
}

player.updateScore(50)
// Prints "50! A new high score for Tomas! 🎉"
// player.highScore == 50

Add functionality to existing types with extensions, and cut down on boilerplate code with custom string interpolations.

let players = getPlayers()
// Sort players, with best high scores first
let ranked = players.sorted(by: { player1, player2 in
	player1.highScore > player2.highScore
})
// Create an array with only the players' names
let rankedNames = ranked.map { $0.name }
// ["Erin", "Rosana", "Tomas"]

Perform powerful custom transformations using streamlined closures.

extension Player: Codable, Equatable {}

import Foundation

let encoder = JSONEncoder()
try encoder.encode(player)
print(player)
// Prints "Player(name: "Tomas", highScore: 50, history: [50])"

Quickly extend your custom types to take advantage of powerful language features, such as automatic JSON encoding and decoding.

Safe

Swift eliminates entire classes of unsafe code. Variables are always initialized before use, arrays and integers are checked for overflow, memory is automatically managed, and potential data races can be spotted at compile time. And Swift heavily leverages value types, especially for commonly used types like Arrays and Dictionaries. This means that when you make a copy of something with that type, you know it won't be modified elsewhere.

Swift also provides a safe way to handle missing values in your code. With optionals, you can explicitly declare when a value may be missing, or nil. And with tools like the if let, guard let, and ?? syntaxes, you can safely check these values before trying to return them, avoiding any surprises or crashes when a nil value is returned.

if let bestPlayer = players.highestScoringPlayer() {
	recordHolder = """
		The record holder is \(bestPlayer.name),\
		with a high score of \(bestPlayer.highScore)!
		"""
} else {
	recordHolder = "No games have been played yet."
}
print(recordHolder)
// The record holder is Erin, with a high score of 271!

let highestScore = players.highestScoringPlayer()?.highScore ?? 0
// highestScore == 271

Features such as optional binding, optional chaining, and nil coalescing let you work safely and efficiently with optional values.

Fast

From its earliest conception, Swift was built to be fast. Using the incredibly high-performance LLVM compiler technology, Swift code is transformed into optimized machine 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 whether it runs in the watch on your wrist or across a cluster of servers. And Swift is the best choice to succeed C++. It includes low-level primitives such as types, flow control, and operators, and provides object-oriented features such as classes, protocols, and generics.

Interoperable

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 coexists alongside your Objective-C and C++ files in the same project, with access to your Objective-C and C++ APIs, making it easy to adopt.

Safely mix C, C++, and Swift

And with the swift-java interoperability project, you can bring Swift code directly into your Java programs, and vice versa — allowing you to adopt Swift at your own pace, and write safe and performant code that interoperates between these two runtimes.

Explore Swift and Java interoperability

Adaptable

Swift is efficient enough to be used in constrained environments like embedded devices, and powerful enough to scale all the way up to servers and cloud infrastructure.

Explore more

Explore frameworks, tools, and programs – all built for developing with Swift.

Swift is developed in the open. To learn more about the open-source Swift project and community, visit Swift.org.