Swift is a general-purpose programming language that's approachable for newcomers and powerful for experts. It is fast, modern, safe, and a joy to write.
struct ScientificName: Codable {
var genus: String
var species: String
var subspecies: String?
}
let momiji = ScientificName(genus: "Acer", species: "palmatum")
let jsonData = try JSONEncoder().encode(momiji)
// {"genus":"Acer","species":"palmatum"}
struct ScientificName {
var genus: String
var species: String
var subspecies: String?
var description: String {
var text = "\(genus) \(species)"
if let subspecies {
// subspecies is guaranteed to be non-nil here.
text += "subsp. \(subspecies)"
}
return text
}
}
func squareWave(phase: Float, overtones: UInt) -> Float {
return (0...overtones)
.map {
let harmonic = Float($0 * 2 + 1)
return sinf(phase * harmonic) / harmonic
}
.reduce(0, +)
}
let hello = "Hello, world!"
let multilineString = """
@@@
@@ @@@@
@@ @@@ @@@@@
@@@@@@@@@ @@@@@
@@@@@@@@@@ @@@@@@
@@@@@@@@@@ @@@@@@
@@@@@@@@@@@@@@@@@
@ @@@@@@@@@@@@@@@
@@@@@@ @@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ @
\(hello)
"""
Use Cases
-
Apple Platforms
Swift is a powerful and intuitive programming language optimized when running on iOS, macOS, and other Apple platforms.
Learn more
Apple offers a wide variety of frameworks and APIs that make applications developed for these platforms unique and fun. -
Cross-platform Command-line
Writing Swift is interactive and fun, the syntax is concise yet expressive. Swift code is safe by design and produces software that runs lightning-fast.
Learn more
SwiftArgumentParser and Swift's growing package ecosystem make developing cross-platform command-line tools a breeze. -
Server and Networking
Swift's small memory footprint, quick startup time, and deterministic performance make it a great choice for server and other networked applications.
Learn more
SwiftNIO and Swift's dynamic server ecosystem bring joy to developing networked applications.
Getting Involved
Everyone is welcome to contribute to Swift. Contributing doesn’t just mean writing code or submitting pull request — there are many different ways for you to get involved, including answering questions on the forums, reporting or triaging bugs, and participating in the Swift evolution process.
No matter how you want to get involved, we ask that you first learn what’s expected of anyone who participates in the project by reading the Community Overview. If you’re contributing code, you should also know how to build and run Swift from the repository, as described in Source Code.
-
Design
Help shape the future of Swift by participating in the Swift evolution process.
Learn more -
Code
Contribute to the Swift compiler, standard library, and other core components of the project.
Learn more -
Troubleshoot
Help improve the quality of Swift by reporting and triaging bugs.
Learn more
What’s New
Stay up-to-date with the latest in the Swift community.