From c4e5f1176949a60cd0f6c65626151826d41c6a2e Mon Sep 17 00:00:00 2001 From: BqLin Date: Sat, 14 Apr 2018 10:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E7=BB=86=E8=8A=82=E4=B8=8E?= =?UTF-8?q?=20markdown=20=E7=BB=9F=E4=B8=80=E6=A0=BC=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20(#779)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修正全角逗号、句号的使用 * 修正逗号使用 * 修正一处代码空格错误 * 修正斜体范围,引用的空格使用 * 修正示例代码错误 * 修正标点,修正示例代码 * 修正标点 * 修正标点 * 添加 Swift 3.1 的更新 * 修改 Swift 3.0.1 位置 * 添加 Swift 4.0.3 更新 * 添加 Swift 4.1 更新 * 修正示例代码 * 修正 markdown 引用语法,优化翻译语句 * 修正示例代码 * 修正标点使用,优化翻译语句 * 修正示例代码 * 修正示例代码 * 优化翻译语句,修正示例代码语法 * 更新示例代码以符合 Swift 4.1 * 优化 markdown 引用格式的使用 * 优化 markdown 行内代码块使用,代码块与正文使用空格分隔 * 人工校验 markdown 行内代码块使用 * 中英文空格分隔 * 移除行末空格 * 人工校验 markdown 行内代码块使用 * 修正 markdown 无序列表使用 --- source/README.md | 2 +- source/SUMMARY.md | 10 +- source/chapter1/01_about_swift.md | 12 +- source/chapter1/02_version_compatibility.md | 2 +- source/chapter1/03_a_swift_tour.md | 38 +- source/chapter1/04_revision_history.md | 46 +- source/chapter2/01_The_Basics.md | 157 +-- source/chapter2/02_Basic_Operators.md | 50 +- source/chapter2/03_Strings_and_Characters.md | 158 +-- source/chapter2/04_Collection_Types.md | 234 ++--- source/chapter2/05_Control_Flow.md | 212 ++-- source/chapter2/06_Functions.md | 76 +- source/chapter2/07_Closures.md | 18 +- source/chapter2/08_Enumerations.md | 66 +- source/chapter2/09_Classes_and_Structures.md | 56 +- source/chapter2/10_Properties.md | 10 +- source/chapter2/11_Methods.md | 73 +- source/chapter2/12_Subscripts.md | 48 +- source/chapter2/13_Inheritance.md | 83 +- source/chapter2/14_Initialization.md | 70 +- source/chapter2/15_Deinitialization.md | 27 +- source/chapter2/16_Optional_Chaining.md | 123 +-- source/chapter2/17_Error_Handling.md | 59 +- source/chapter2/18_Type_Casting.md | 8 +- source/chapter2/19_Nested_Types.md | 10 +- source/chapter2/21_Protocols.md | 29 +- source/chapter2/22_Generics.md | 36 +- .../23_Automatic_Reference_Counting.md | 231 +++-- source/chapter2/25_Access_Control.md | 10 +- source/chapter2/26_Advanced_Operators.md | 4 +- .../01_About_the_Language_Reference.md | 4 +- source/chapter3/02_Lexical_Structure.md | 252 ++--- source/chapter3/03_Types.md | 180 ++-- source/chapter3/04_Expressions.md | 292 +++--- source/chapter3/05_Statements.md | 384 +++---- source/chapter3/06_Declarations.md | 422 ++++---- source/chapter3/07_Attributes.md | 38 +- source/chapter3/08_Patterns.md | 58 +- .../09_Generic_Parameters_and_Arguments.md | 42 +- source/chapter3/10_Summary_of_the_Grammar.md | 942 +++++++++--------- source/chapter4/01_Access_Control.md | 38 +- source/chapter4/02_Type_Custom.md | 52 +- source/chapter4/03_Ballons.md | 12 +- .../04_Interacting_with_C_Pointers.md | 24 +- .../chapter4/05_Value_and_Reference_Types.md | 30 +- .../06_Access_Control_and_Protected.md | 28 +- source/chapter4/07_Optional_Case_Study.md | 32 +- source/v1.0.md | 12 +- 48 files changed, 2414 insertions(+), 2386 deletions(-) diff --git a/source/README.md b/source/README.md index 875989cb..ef91745c 100755 --- a/source/README.md +++ b/source/README.md @@ -1,6 +1,6 @@ > 2016.9.23: 已经更新到 Swift 3.0。 # 3.0 更新说明 -Swift 3.0 是自 Swift 开源以来第一个大的版本更新。从语言角度不兼容之前的 Swift 2.2 和 Swift 2.3 版本。Swift 3.0 的更新说明,大家可以查看[官方blog的说明](https://swift.org/blog/swift-3-0-released/),也可以关注 [SwiftGG](http://swift.gg) 最新的文章。学习官方文档,是掌握语言特性点的最佳途径,感谢翻译的小伙伴们为 Swift 社区所做贡献! +Swift 3.0 是自 Swift 开源以来第一个大的版本更新。从语言角度不兼容之前的 Swift 2.2 和 Swift 2.3 版本。Swift 3.0 的更新说明,大家可以查看[官方 blog 的说明](https://swift.org/blog/swift-3-0-released/),也可以关注 [SwiftGG](http://swift.gg) 最新的文章。学习官方文档,是掌握语言特性点的最佳途径,感谢翻译的小伙伴们为 Swift 社区所做贡献! # 3.0 译者记录 相关[issue](https://github.com/numbbbbb/the-swift-programming-language-in-chinese/issues/628) diff --git a/source/SUMMARY.md b/source/SUMMARY.md index cb662fbc..63c518a5 100755 --- a/source/SUMMARY.md +++ b/source/SUMMARY.md @@ -45,11 +45,11 @@ * [泛型参数](chapter3/09_Generic_Parameters_and_Arguments.md) * [语法总结](chapter3/10_Summary_of_the_Grammar.md) -* 苹果官方Blog官方翻译 +* 苹果官方 Blog 官方翻译 * [Access Control 权限控制的黑与白](chapter4/01_Access_Control.md) - * [造个类型不是梦-白话Swift类型创建](chapter4/02_Type_Custom.md) - * [WWDC里面的那个“大炮打气球”](chapter4/03_Ballons.md) - * [Swift与C语言指针友好合作](chapter4/04_Interacting_with_C_Pointers.md) + * [造个类型不是梦-白话 Swift 类型创建](chapter4/02_Type_Custom.md) + * [WWDC 里面的那个“大炮打气球”](chapter4/03_Ballons.md) + * [Swift 与 C 语言指针友好合作](chapter4/04_Interacting_with_C_Pointers.md) * [引用类型和值类型的恩怨](chapter4/05_Value_and_Reference_Types.md) - * [访问控制和Protected](chapter4/06_Access_Control_and_Protected.md) + * [访问控制和 Protected](chapter4/06_Access_Control_and_Protected.md) * [可选类型完美解决占位问题](chapter4/07_Optional_Case_Study.md) \ No newline at end of file diff --git a/source/chapter1/01_about_swift.md b/source/chapter1/01_about_swift.md index 06f77007..c35770b7 100755 --- a/source/chapter1/01_about_swift.md +++ b/source/chapter1/01_about_swift.md @@ -8,10 +8,14 @@ > 2.0 > 翻译+校对:[xtymichael](https://github.com/xtymichael) -> 3.0 翻译+校对:[shanks](http://codebuild.me),2016-10-06 -> 3.0.1 review : 2016-11-09 +> 3.0 +> 翻译+校对:[shanks](http://codebuild.me),2016-10-06 -> 3.1 校对: [SketchK](https://github.com/SketchK) 2017-04-08 +> 3.0.1 +> review : 2016-11-09 + +> 3.1 +> 校对: [SketchK](https://github.com/SketchK) 2017-04-08 > 4.0 > 翻译:[rain2540](https://github.com/rain2540) 2017-09-21 @@ -23,7 +27,7 @@ Swift 是一种非常好的编写软件的方式,无论是手机,台式机 Swift 对于初学者来说也很友好。它是第一个既满足工业标准又像脚本语言一样充满表现力和趣味的系统编程语言。它支持代码预览(playgrounds),这个革命性的特性可以允许程序员在不编译和运行应用程序的前提下运行 Swift 代码并实时查看结果。 -Swift通过采用现代编程模式来避免大量常见编程错误: +Swift 通过采用现代编程模式来避免大量常见编程错误: * 变量始终在使用前初始化。 * 检查数组索引超出范围的错误。 diff --git a/source/chapter1/02_version_compatibility.md b/source/chapter1/02_version_compatibility.md index 26f71329..0c5fb945 100755 --- a/source/chapter1/02_version_compatibility.md +++ b/source/chapter1/02_version_compatibility.md @@ -10,7 +10,7 @@ 本书描述的是 Swift 4.1,是 Xcode 9.2 中包含的默认版本。你可以用 Xcode 9.2 来构建用 Swift 4 或 Swift 3 写的项目。 > 注意 -> +> > 当 Swift 4 编译器编译 Swift 3 版本的代码时,它识别的语言版本为 3.2 版本。因此,你可以使用像 `#if swift(>=3.2)` 条件编译块来编写多版本编译器可以并存的代码。 当你用 Xcode 9.2 编译 Swift 3 的代码,Swift 4 中大部分功能是可以使用的。也就是说,下面的功能仅仅是 Swift 4 的代码中可以使用: diff --git a/source/chapter1/03_a_swift_tour.md b/source/chapter1/03_a_swift_tour.md index 3d1f36ed..9012334d 100755 --- a/source/chapter1/03_a_swift_tour.md +++ b/source/chapter1/03_a_swift_tour.md @@ -10,13 +10,15 @@ > 翻译+校对:[xtymichael](https://github.com/xtymichael) > 2.2 -> 翻译:[175](https://github.com/Brian175),2016-04-09 校对:[SketchK](https://github.com/SketchK),2016-05-11 -> +> 翻译:[175](https://github.com/Brian175),2016-04-09 +> 校对:[SketchK](https://github.com/SketchK),2016-05-11 + > 3.0 > 翻译+校对:[shanks](http://codebuild.me),2016-10-06 -> 3.0.1 review: 2016-11-09 -> +> 3.0.1 +> review: 2016-11-09 + > 3.1 校对: [SketchK](https://github.com/SketchK) 2017-04-08 > 4.0 @@ -27,14 +29,14 @@ 本页内容包括: -- [简单值(Simple Values)](#simple_values) -- [控制流(Control Flow)](#control_flow) -- [函数和闭包(Functions and Closures)](#functions_and_closures) -- [对象和类(Objects and Classes)](#objects_and_classes) -- [枚举和结构体(Enumerations and Structures)](#enumerations_and_structures) -- [协议和扩展(Protocols and Extensions)](#protocols_and_extensions) -- [错误处理(Error Handling)](#error_handling) -- [泛型(Generics)](#generics) +- [简单值(Simple Values)](#simple_values) +- [控制流(Control Flow)](#control_flow) +- [函数和闭包(Functions and Closures)](#functions_and_closures) +- [对象和类(Objects and Classes)](#objects_and_classes) +- [枚举和结构体(Enumerations and Structures)](#enumerations_and_structures) +- [协议和扩展(Protocols and Extensions)](#protocols_and_extensions) +- [错误处理(Error Handling)](#error_handling) +- [泛型(Generics)](#generics) 通常来说,编程语言教程中的第一个程序应该在屏幕上打印 “Hello, world”。在 Swift 中,可以用一行代码实现: @@ -48,8 +50,8 @@ print("Hello, world!") > 注意 > -> 最好的体验是把这一章作为Playground文件在Xcode中打开。 Playgrounds允许你可以编辑代码并立刻看到输出结果。 -> +> 最好的体验是把这一章作为 Playground 文件在 Xcode 中打开。 Playgrounds 允许你可以编辑代码并立刻看到输出结果。 +> > [Download Playground](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.playground.zip) @@ -74,7 +76,7 @@ let explicitDouble: Double = 70 ``` > 练习 -> +> > 创建一个常量,显式指定类型为 `Float` 并指定初始值为 4。 值永远不会被隐式转换为其他类型。如果你需要把一个值转换成其他类型,请显式转换。 @@ -140,7 +142,7 @@ occupations = [:] ## 控制流 -使用 `if` 和 `switch` 来进行条件操作,使用 `for-in`、 `while` 和 `repeat-while` 来进行循环。包裹条件和循环变量的括号可以省略,但是语句体的大括号是必须的。 +使用 `if` 和 `switch` 来进行条件操作,使用 `for-in`、`while` 和 `repeat-while` 来进行循环。包裹条件和循环变量的括号可以省略,但是语句体的大括号是必须的。 ```swift let individualScores = [75, 43, 103, 87, 12] @@ -157,7 +159,7 @@ print(teamScore) 在 `if` 语句中,条件必须是一个布尔表达式——这意味着像 `if score { ... }` 这样的代码将报错,而不会隐形地与 0 做对比。 -你可以一起使用 `if` 和 `let` 一起来处理值缺失的情况。这些值可由可选值来代表。一个可选的值是一个具体的值或者是 `nil` 以表示值缺失。在类型后面加一个问号(`?ß`)来标记这个变量的值是可选的。 +你可以一起使用 `if` 和 `let` 一起来处理值缺失的情况。这些值可由可选值来代表。一个可选的值是一个具体的值或者是 `nil` 以表示值缺失。在类型后面加一个问号(`?`)来标记这个变量的值是可选的。 ```swift var optionalString: String? = "Hello" @@ -713,7 +715,7 @@ print(protocolValue.simpleDescription) // print(protocolValue.anotherProperty) // 去掉注释可以看到错误 ``` -即使 `protocolValue` 变量运行时的类型是 `simpleClass` ,编译器还是会把它的类型当做`ExampleProtocol`。这表示你不能调用在协议之外的方法或者属性。 +即使 `protocolValue` 变量运行时的类型是 `simpleClass` ,编译器还是会把它的类型当做 `ExampleProtocol`。这表示你不能调用在协议之外的方法或者属性。 ## 错误处理 diff --git a/source/chapter1/04_revision_history.md b/source/chapter1/04_revision_history.md index b54d96b1..56a20332 100644 --- a/source/chapter1/04_revision_history.md +++ b/source/chapter1/04_revision_history.md @@ -187,10 +187,10 @@ 更新自动引用计数章节中关于 weak 和 unowned 引用的讨论。
  • - 增加声明标识符章节中关于新的标识符`unowned`,`unowend(safe)`和`unowned(unsafe)`的描述。 + 增加声明标识符章节中关于新的标识符 `unowned`,`unowend(safe)` 和 `unowned(unsafe)` 的描述。
  • - 增加Any 和 AnyObject 的类型转换一节中关于使用类型`Any`作为可选值的描述。 + 增加Any 和 AnyObject 的类型转换一节中关于使用类型 `Any` 作为可选值的描述。
  • 更新表达式章节,把括号表达式和元组表达式的描述分开。 @@ -450,11 +450,11 @@ 增加了枚举一章的递归枚举一节和声明一章的任意类型用例的枚举一节中关于递归枚举的内容。
  • - 增加了控制流一章中a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html#//apple_ref/doc/uid/TP40014097-CH9-ID523">检查 API 可用性一节和语句一章中可用性条件一节中关于 API 可用性检查的内容。 + 增加了控制流一章中 a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html#//apple_ref/doc/uid/TP40014097-CH9-ID523">检查 API 可用性一节和语句一章中可用性条件一节中关于 API 可用性检查的内容。
  • - 增加了控制流一章的早期退出一节和语句一章的guard语句中关于新 guard 语句的内容。 + 增加了控制流一章的早期退出一节和语句一章的guard 语句中关于新 guard 语句的内容。
  • 增加了协议一章中协议扩展一节中关于协议扩展的内容。 @@ -577,7 +577,7 @@ 更新至 Swift 1.2。
  • - Swift现在自身提供了一个Set集合类型,更多信息请看集合 + Swift 现在自身提供了一个Set集合类型,更多信息请看集合
  • @@ -587,7 +587,7 @@ 对于类型属性和方法现在可以使用static关键字作为声明描述符,更多信息,请看类型变量属性
  • - Swift现在包含一个as?as!的向下可失败类型转换运算符。更多信息,请看协议遵循性检查 + Swift 现在包含一个as?as!的向下可失败类型转换运算符。更多信息,请看协议遵循性检查
  • 增加了一个新的指导章节,它是关于字符串索引的 @@ -599,7 +599,7 @@ 更新了常量和常量属性在声明和构造时的规则,更多信息,请看常量声明
  • - 更新了字符串字面量中Unicode标量集的定义,请看字符串字面量中的特殊字符 + 更新了字符串字面量中 Unicode 标量集的定义,请看字符串字面量中的特殊字符
  • 更新了区间运算符章节来提示当半开区间运算符含有相同的起止索引时,其区间为空。 @@ -617,7 +617,7 @@ 更新了捕获列表章节来澄清对于闭包捕获列表中的弱引用和无主引用的使用语法。
  • - 更新了运算符章节来明确指明一些例子来说明自定义运算符所支持的特性,如数学运算符,各种符号,Unicode符号块等 + 更新了运算符章节来明确指明一些例子来说明自定义运算符所支持的特性,如数学运算符,各种符号,Unicode 符号块等
  • 在函数作用域中的常量声明时可以不被初始化,它必须在第一次使用前被赋值。更多的信息,请看常量声明 @@ -673,7 +673,7 @@ 带有原始值的枚举类型增加了一个rawValue属性替代toRaw()方法,同时使用了一个以rawValue为参数的失败构造器来替代fromRaw()方法。更多的信息,请看原始值(Raw Values)带原始值的枚举类型(Enumerations with Cases of a Raw-Value Type)部分。
  • - 自定义运算符现在可以包含`?`字符,更新的运算符(Operators)章节描述了改进后的规则,并且从自定义运算符(Custom Operators)章节删除了重复的运算符有效字符集合 + 自定义运算符现在可以包含 `?` 字符,更新的运算符(Operators)章节描述了改进后的规则,并且从自定义运算符(Custom Operators)章节删除了重复的运算符有效字符集合
  • @@ -697,7 +697,7 @@ 2014-08-18