|
1 | 1 | --- |
2 | 2 | layout: page |
3 | | -title: About Swift |
| 3 | +title: 关于 Swift |
4 | 4 | --- |
5 | 5 |
|
6 | | -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. |
| 6 | +Swift 是一种通用编程语言,对新手友好,同时也足够强大,能满足专业需求。它快速、现代、安全,并且编写起来充满乐趣。 |
7 | 7 |
|
8 | | -* Swift is general-purpose and modern. Suitable for everything from systems programming, through mobile and desktop apps, to cloud services. |
9 | | -* Swift is safe. Undefined behavior is the enemy of safety, and it’s best to catch mistakes before software goes into production. Swift makes the obvious path the safest. |
10 | | -* Swift is fast to run and quick to write. It comes with predictable and consistent performance that is on-par with C-based languages without sacrificing developer friendliness. |
11 | | -* Swift is approachable and powerful. From a single-line “Hello, World!” to large-scale apps with hundreds of thousands of lines. Swift scales with your needs. |
| 8 | +* Swift 是通用且现代的:适用于从系统编程到移动和桌面应用,再到云服务的各种场景。 |
| 9 | +* Swift 是安全的:未定义行为是安全的敌人,且最好在软件投入生产前就捕获错误。Swift 让最明显的路径成为最安全的选择。 |
| 10 | +* Swift 运行快,编写也高效:它提供可预测且一致的性能,与基于 C 的编程语言性能相当,同时没有牺牲对开发的友好性。 |
| 11 | +* Swift 既简单易学又功能强大:从简单的单行代码的“Hello, World!”到拥有数十万行代码的大型应用,Swift 都能按你的需求扩展。 |
12 | 12 |
|
13 | | -## Tools |
| 13 | +## 工具 |
14 | 14 |
|
15 | | -Tools are a critical part of the Swift ecosystem. We strive to integrate well within a developer's toolset, to build quickly, to present excellent diagnostics, and to enable interactive development experiences. Tools can make programming so much more powerful, like Swift-based playgrounds do in Xcode, or a web-based REPL can when working with Linux server-side code. |
| 15 | +工具是 Swift 生态系统的重要组成部分。我们致力于与开发者的工具集良好集成,快速构建,提供出色的诊断功能,并支持交互式开发体验。工具能够极大地提升编程的能力,比如 Xcode 中基于 Swift 的 Playground,或在处理 Linux 服务端代码时的基于 Web 的 REPL。 |
16 | 16 |
|
17 | | -## Features |
| 17 | +## 特性 |
18 | 18 |
|
19 | | -Swift includes features that make code easier to read and write, while giving the developer the control needed in a true systems programming language. Swift supports inferred types to make code cleaner and less prone to mistakes, and modules eliminate headers and provide namespaces. Memory is managed automatically, and you don’t even need to type semi-colons. Swift also borrows from other languages, for instance named parameters brought forward from Objective-C are expressed in a clean syntax that makes APIs in Swift easy to read and maintain. |
| 19 | +Swift 拥有许多特性,使代码更易读易写,同时赋予开发者在真正系统编程语言中所需的控制力。Swift 支持类型推断,让代码更简洁、更不易出错;Swift 的模块消灭了头文件并提供了命名空间;Swift 的内存管理是自动化的;Swift 代码中甚至无需输入分号。此外,Swift 借鉴了其他语言的优势,例如从 Objective-C 引入的命名参数,通过简洁的语法表达,使 Swift 的 API 易于阅读和维护。 |
20 | 20 |
|
21 | | -The features of Swift are designed to work together to create a language that is powerful, yet fun to use. Some additional features of Swift include: |
| 21 | +Swift 的特性相辅相成,打造出一种强大却又有趣的实用编程语言。Swift 的一些其他的特性包括: |
22 | 22 |
|
23 | | -* Closures unified with function pointers |
24 | | -* Tuples and multiple return values |
25 | | -* Generics |
26 | | -* Fast and concise iteration over a range or collection |
27 | | -* Structs that support methods, extensions, and protocols |
28 | | -* Functional programming patterns, e.g., map and filter |
29 | | -* Powerful error handling built-in |
30 | | -* Advanced control flow with `do`, `guard`, `defer`, and `repeat` keywords |
| 23 | +* 闭包与函数指针的统一 |
| 24 | +* 元组与多返回值的支持 |
| 25 | +* 泛型 |
| 26 | +* 对范围(Range)和集合(Collection)类型快速简洁的遍历 |
| 27 | +* 支持方法(method)、扩展(extension)和协议(protocol)的结构体(Struct) |
| 28 | +* 函数式编程模式,例如 map 和 filter |
| 29 | +* 内置强大的错误处理机制 |
| 30 | +* 使用 `do`、`guard`、`defer` 和 `repeat` 关键字实现高级控制流 |
31 | 31 |
|
32 | | -### Safety |
| 32 | +### 安全 |
33 | 33 |
|
34 | | -Swift was designed from the outset to be safer than C-based languages, and 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`). |
| 34 | +Swift 从一开始就设计得比基于 C 的语言更安全,并消除了各种不安全代码的问题。变量在使用前必须初始化,数组和整数会进行溢出检查,内存管理是自动化的。语法经过优化,便于清晰表达意图,例如使用简单的三个字符关键字定义一个变量(`var`)或常量(`let`)。 |
35 | 35 |
|
36 | | -Another safety feature is that by default Swift objects can never be `nil`, and trying to make or use a `nil` object results in a compile-time error. This makes writing code much cleaner and safer, and prevents a common cause of runtime crashes. However, there are cases where `nil` is appropriate, and 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 ``?`` to indicate to the compiler you understand the behavior and will handle it safely. |
| 36 | +另一个安全特性是 Swift 对象(object)在默认情况下不能为 `nil`,尝试创建或使用 `nil` 对象会导致编译时错误。这使代码编写更清晰、更安全,并避免了一种运行时崩溃的常见原因。然而,在某些情况下,`nil` 是合适的,为此 Swift 提供了一项创新特性,称为 **可选值(optionals)**。可选值可以包含 `nil` 值,但 Swift 的语法要求你使用 ``?`` 向编译器明确表示你理解这种行为并会安全地处理它,从而强制实现安全的可选值操作。 |
37 | 37 |
|
38 | 38 | {% include_relative _platform-support.md %} |
39 | 39 | {% include_relative _open-source.md %} |
0 commit comments