Fast
Build with speed and performance.
Swift meets the most performance-critical needs, while allowing your code to remain expressive and approachable. Swift compiles directly to native code and provides predictable memory management.
Tools for Linux, macOS, and Windows
Swift is the only language that scales from embedded devices and kernels to apps and cloud infrastructure. It’s simple, and expressive, with incredible performance and safety. And it has unmatched interoperability with C and C++.
It's the combination of approachability, speed, safety, and all of
Swift’s strengths that make it so unique.Build with speed and performance.
Swift meets the most performance-critical needs, while allowing your code to remain expressive and approachable. Swift compiles directly to native code and provides predictable memory management.
// Vectorized check that a utf8 buffer is all ASCII
func isASCII(utf8: Span<SIMD16<UInt8>>) -> Bool {
// combine all the code units into a single entry
utf8.indices.reduce(into: SIMD16()) {
// fold each set of code units into the result
$0 |= utf8[$1]
}
// check that every entry is in the ASCII range
.max() < 0x80
}
Concise code. Powerful results.
Swift empowers you to write advanced code in a concise, readable syntax that even a beginner can understand. Swift supports object-oriented, functional, and generic programming patterns that experienced developers are familiar with. Its progressive disclosure allows you to pick up the language quickly, taking advantage of power-user features as you need them.
import ArgumentParser
// Complete implementation of a command line tool
@main struct Describe: ParsableCommand {
@Argument(help: "The values to describe.")
var values: [Double] = []
mutating func run() {
values.sort()
let total = values.reduce(0, +)
print(
"""
Smallest: \(values.first, default: "No value")
Total: \(total)
Mean: \(total / Double(values.count))
""")
}
}
Protect memory safety.
Swift prioritizes safety and eliminates entire classes of bugs and vulnerabilities by its design. Memory safety and data race safety are core features of the language, making them straightforward to integrate into your codebase. Safety is required at compile time, before your applications are ever run.
let transform = Affine2DTransformBuilder()
.translate([10.0, 20.0].span)
.rotate(30.0)
.build()
let v = [11.0, 22.0, 1.0]
// Call C functions safely with Swift types
let u = mat_vec_mul(
transform, rowCount, colCount, v.span, allocator)
let uMagnitude = vec_mag(u.span)
Adopt in existing code incrementally.
Swift provides unmatched interoperability with its combination of natively understanding C and C++ types without the need for foreign function interfaces, and by providing bridging for bi-directional access. Swift’s interoperability features allow you to incrementally adopt the language into existing codebases without requiring a full code rewrite.
import CxxStdlib
// Use types from C++, like std::string, directly
let beverages: [std.string] = [
"apple juice", "grape juice", "green tea"
]
let juices = beverages.filter { cppstring in
// and call methods directly on C++ types
cppstring.find(.init("juice")) != std.string.npos
}
From microcontrollers to servers.
The only language that can span from embedded and kernel, to server and apps. Swift excels no matter where it’s used: from constrained environments like firmware where every byte counts, to cloud services handling billions of requests a day.
// Configure UART by direct register manipulation
// using Swift MMIO. Enables RX and TX, and sets
// baud rate to 115,200. Compiles down to an
// optimal assembly sequence with no overhead.
usart1.brr.modify { rw in
rw.raw.brr_field = 16_000_000 / 115_200
}
usart1.cr1.modify { rw in
rw.ue = .Enabled
rw.re = .Enabled
rw.te = .Enabled
}
Contribute and get involved.
宝宝吃什么鱼比较好 | 梦见梨是什么意思 | 脂肪肝吃什么药好得快 | 1947年属什么生肖 | 大枣和红枣有什么区别 |
白斑不能吃什么 | 下午三点是什么时辰 | 吉吉念什么 | 小燕子的尾巴像什么 | 子宫疼是什么原因 |
尿频看什么科 | 1月份是什么星座的人 | 印第安人属于什么人种 | 一个木一个舌读什么 | 左右逢源是什么生肖 |
连铁是什么器官 | 鹦鹉吃什么蔬菜 | 血脂高吃什么药效果好 | 头疼应该挂什么科 | 子宫切除后要注意什么 |
人不出汗是什么原因adwl56.com | 女人做爱什么感觉hcv8jop8ns5r.cn | 什么叫情商imcecn.com | 助教是干什么的hcv8jop1ns2r.cn | 水黄是什么原因hcv9jop5ns9r.cn |
一吃东西就牙疼是什么原因引起的hcv8jop3ns9r.cn | 献血后吃什么补血最快shenchushe.com | 妇科和妇产科有什么区别hcv8jop0ns3r.cn | 昔日是什么意思hcv8jop6ns4r.cn | 夏天什么时候结束hcv7jop6ns9r.cn |
男性看下面挂什么科室hcv7jop6ns0r.cn | 慢性肾炎是什么原因引起的hcv9jop5ns7r.cn | 女人吃芡实有什么好处shenchushe.com | 雅漾喷雾有什么功效hcv8jop9ns3r.cn | 什么是繁体字hcv9jop1ns9r.cn |
流产有什么症状hcv9jop1ns9r.cn | mpa是什么意思hcv8jop5ns6r.cn | 蜂蜜与什么食物相克hcv9jop3ns2r.cn | 九月二十五是什么星座hcv8jop9ns6r.cn | 什么口红好hcv7jop7ns2r.cn |