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.
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.
Declare new types with modern, straightforward syntax, provide default values for instance properties, and define custom initializers.
extensionPlayer {
mutatingfuncupdateScore(_newScore: Int) {
history.append(newScore)
ifhighScore < 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.
Perform powerful custom transformations using streamlined closures.
letplayers = getPlayers()
// Sort players, with best high scores firstletranked = players.sorted(by: { player1, player2inplayer1.highScore > player2.highScore
})
// Create an array with only the players’ namesletrankedNames = ranked.map { 0ドル.name }
// ["Erin", "Rosana", "Tomas"]
Quickly extend your custom types to take advantage of powerful language features, such as automatic JSON encoding and decoding.
Fast
Optimized for Apple platforms
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.
Safe
Straightforward safety
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.
ifletbestPlayer = 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!lethighestScore = 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.
Adaptable
From microcontrollers to servers
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.
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.
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.
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.