From ad1d3944bcc08942f3ce9a2f2fefeadc9ba57dc4 Mon Sep 17 00:00:00 2001 From: bqlin Date: Wed, 14 Feb 2018 19:41:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=86=97=E4=BD=99=E7=A9=BA?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chapter1/01_a_bout_Swift.md | 35 +++++++++---------- source/chapter1/02_version_compatibility.md | 1 - source/chapter1/03_a_swift_tour.md | 5 +-- source/chapter1/04_revision_history.md | 26 ++++++-------- source/chapter2/02_Basic_Operators.md | 2 -- source/chapter2/03_Strings_and_Characters.md | 17 --------- source/chapter2/04_Collection_Types.md | 2 -- source/chapter2/05_Control_Flow.md | 9 ----- source/chapter2/06_Functions.md | 12 ------- source/chapter2/07_Closures.md | 2 -- source/chapter2/08_Enumerations.md | 3 -- source/chapter2/09_Classes_and_Structures.md | 1 - source/chapter2/10_Properties.md | 4 --- source/chapter2/11_Methods.md | 1 - source/chapter2/12_Subscripts.md | 17 +++++---- source/chapter2/14_Initialization.md | 3 -- source/chapter2/18_Error_Handling.md | 1 - source/chapter2/19_Type_Casting.md | 1 - source/chapter2/21_Extensions.md | 1 - source/chapter2/22_Protocols.md | 2 -- source/chapter2/25_Advanced_Operators.md | 3 -- source/chapter3/02_Lexical_Structure.md | 7 ---- source/chapter3/04_Expressions.md | 1 - source/chapter3/05_Declarations.md | 5 --- .../08_Generic_Parameters_and_Arguments.md | 2 -- source/chapter3/09_Summary_of_the_Grammar.md | 7 ---- source/chapter3/10_Statements.md | 1 - source/chapter4/01_Access_Control.md | 2 -- source/chapter4/02_Type_Custom.md | 7 ---- source/chapter4/03_Ballons.md | 2 -- .../chapter4/05_Value_and_Reference_Types.md | 1 - source/chapter4/07_Optional_Case_Study.md | 2 -- source/v1.0.md | 1 - 33 files changed, 37 insertions(+), 149 deletions(-) diff --git a/source/chapter1/01_a_bout_Swift.md b/source/chapter1/01_a_bout_Swift.md index 36c49572..ac380a96 100755 --- a/source/chapter1/01_a_bout_Swift.md +++ b/source/chapter1/01_a_bout_Swift.md @@ -1,13 +1,13 @@ -# 关于 Swift(About Swift) ------------------ - -> 1.0 -> 翻译:[numbbbbb](https://github.com/numbbbbb) -> 校对:[yeahdongcn](https://github.com/yeahdongcn) - -> 2.0 -> 翻译+校对:[xtymichael](https://github.com/xtymichael) -> +# 关于 Swift(About Swift) +----------------- + +> 1.0 +> 翻译:[numbbbbb](https://github.com/numbbbbb) +> 校对:[yeahdongcn](https://github.com/yeahdongcn) + +> 2.0 +> 翻译+校对:[xtymichael](https://github.com/xtymichael) +> > 3.0 翻译+校对:[shanks](http://codebuild.me),2016-10-06 > 3.0.1 review : 2016-11-09 > @@ -15,8 +15,7 @@ > > 4.0 > 翻译:[rain2540](https://github.com/rain2540) 2017-09-21 -> - +> Swift 是一种非常好的编写软件的方式,无论是手机,台式机,服务器,还是其他运行代码的设备。它是一种安全,快速和互动的编程语言,将现代编程语言的精华和苹果工程师文化的智慧,以及来自开源社区的多样化贡献结合了起来。编译器对性能进行了优化,编程语言对开发进行了优化,两者互不干扰,鱼与熊掌兼得。 @@ -24,12 +23,12 @@ Swift 对于初学者来说也很友好。它是第一个既满足工业标准 Swift通过采用现代编程模式来避免大量常见编程错误: -* 变量始终在使用前初始化。 -* 检查数组索引超出范围的错误。 -* 检查整数是否溢出。 -* 可选值确保明确处理 nil 值。 -* 内存被自动管理。 -* 错误处理允许从意外故障控制恢复。 +* 变量始终在使用前初始化。 +* 检查数组索引超出范围的错误。 +* 检查整数是否溢出。 +* 可选值确保明确处理 nil 值。 +* 内存被自动管理。 +* 错误处理允许从意外故障控制恢复。 Swift 代码被编译和优化,以充分利用现代硬件。语法和标准库是基于指导原则设计的,编写代码的明显方式也应该是最好的。安全性和速度的结合使得 Swift 成为从 “Hello,world!” 到整个操作系统的绝佳选择。 diff --git a/source/chapter1/02_version_compatibility.md b/source/chapter1/02_version_compatibility.md index 2754bd3c..d98fb40d 100755 --- a/source/chapter1/02_version_compatibility.md +++ b/source/chapter1/02_version_compatibility.md @@ -12,7 +12,6 @@ 当你用 Xcode 编译 Swift 3 的代码,Swift 4 中大部分功能是可以使用的。也就是说,下面的功能仅仅是 Swift 4 的代码中可以使用: - * 字符串的子串操作返回的实例是 `Substring` 类型,不再是 `String` 类型。 * 在一些地方显式的添加 `@objc` 属性。 * 同一文件中一个类型的 extension 可以访问这个类型的 private 属性。 diff --git a/source/chapter1/03_a_swift_tour.md b/source/chapter1/03_a_swift_tour.md index e01142bc..cffd3172 100755 --- a/source/chapter1/03_a_swift_tour.md +++ b/source/chapter1/03_a_swift_tour.md @@ -17,8 +17,7 @@ > 3.0.1 review: 2016-11-09 > -> 3.1 校对: [SketchK](https://github.com/SketchK) 2017-04-08 - +> 3.1 校对: [SketchK](https://github.com/SketchK) 2017-04-08 > 4.0 > 翻译+校对:[muhlenxi](https://github.com/muhlenxi) 2017-09-26 @@ -522,7 +521,6 @@ let sideLength = optionalSquare?.sideLength ## 枚举和结构体 - 使用 `enum` 来创建一个枚举。就像类和其他所有命名类型一样,枚举可以包含方法。 ```swift @@ -630,7 +628,6 @@ let threeOfSpadesDescription = threeOfSpades.simpleDescription() > 练习: > 给 `Card` 添加一个方法,创建一副完整的扑克牌并把每张牌的 rank 和 suit 对应起来。 - ## 协议和扩展 diff --git a/source/chapter1/04_revision_history.md b/source/chapter1/04_revision_history.md index 287beee9..ae65b7d3 100644 --- a/source/chapter1/04_revision_history.md +++ b/source/chapter1/04_revision_history.md @@ -2,28 +2,28 @@ --- -> 1.0 -> 翻译:[成都老码团队翻译组-Arya](http://weibo.com/littlekok/) -> 校对:[成都老码团队翻译组-Oberyn](http://weibo.com/u/5241713117) -[changkun](http://changkun.us/about/) -> -> 1.1 +> 1.0 > 翻译:[成都老码团队翻译组-Arya](http://weibo.com/littlekok/) > 校对:[成都老码团队翻译组-Oberyn](http://weibo.com/u/5241713117) [changkun](http://changkun.us/about/) > -> 1.2 +> 1.1 > 翻译:[成都老码团队翻译组-Arya](http://weibo.com/littlekok/) > 校对:[成都老码团队翻译组-Oberyn](http://weibo.com/u/5241713117) [changkun](http://changkun.us/about/) -> -> 2.0 +> +> 1.2 +> 翻译:[成都老码团队翻译组-Arya](http://weibo.com/littlekok/) +> 校对:[成都老码团队翻译组-Oberyn](http://weibo.com/u/5241713117) +[changkun](http://changkun.us/about/) +> +> 2.0 > 翻译+校对:[changkun](http://changkun.us/about/) > -> 2.1 +> 2.1 > 翻译+校对:[changkun](http://changkun.us/about/) > -> 2.2 +> 2.2 > 翻译+校对:[changkun](http://changkun.us/about/) > > 3.0 @@ -80,7 +80,6 @@ - ### Swift 3.0 更新 @@ -124,7 +123,6 @@
  • 更新泛型章节中泛型 Where 语句一节和泛型形参和实参章节,现在泛型的 where 语句写在一个声明的最后。 -
  • 更新逃逸闭包一节,现在闭包默认为非逃逸的(noescaping)。 @@ -453,7 +451,6 @@ - ### Swift 1.2 更新 @@ -539,7 +536,6 @@ - ### Swift 1.1 更新 diff --git a/source/chapter2/02_Basic_Operators.md b/source/chapter2/02_Basic_Operators.md index 02a3f06f..5e79e4ea 100755 --- a/source/chapter2/02_Basic_Operators.md +++ b/source/chapter2/02_Basic_Operators.md @@ -146,7 +146,6 @@ Swift 中所有数值类型都支持了基本的四则*算术运算符*: 在对负数 `b` 求余时,`b` 的符号会被忽略。这意味着 `a % b` 和 `a % -b` 的结果是相同的。 - ### 一元负号运算符 数值的正负号可以使用前缀 `-`(即*一元负号符*)来切换: @@ -170,7 +169,6 @@ let alsoMinusSix = +minusSix // alsoMinusSix 等于 -6 虽然一元正号符什么都不会改变,但当你在使用一元负号来表达负数时,你可以使用一元正号来表达正数,如此你的代码会具有对称美。 - ## 组合赋值运算符 diff --git a/source/chapter2/03_Strings_and_Characters.md b/source/chapter2/03_Strings_and_Characters.md index 49da955c..90155489 100755 --- a/source/chapter2/03_Strings_and_Characters.md +++ b/source/chapter2/03_Strings_and_Characters.md @@ -52,7 +52,6 @@ Swift 的`String`和`Character`类型提供了快速和兼容 Unicode 的方式 > Swift 的`String`类型与 Foundation `NSString`类进行了无缝桥接。Foundation 也可以对`String`进行扩展,暴露在`NSString`中定义的方法。 这意味着,如果你在`String`中调用这些`NSString`的方法,将不用进行转换。 > 更多关于在 Foundation 和 Cocoa 中使用`String`的信息请查看 *[Using Swift with Cocoa and Objective-C (Swift 4)](https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html#//apple_ref/doc/uid/TP40014216-CH6)*。 - ## 字符串字面量 @@ -168,7 +167,6 @@ if emptyString.isEmpty { // 打印输出:"Nothing to see here" ``` - ## 字符串可变性 @@ -187,7 +185,6 @@ constantString += " and another Highlander" > 注意: 在 Objective-C 和 Cocoa 中,您需要通过选择两个不同的类(`NSString`和`NSMutableString`)来指定字符串是否可以被修改。 - ## 字符串是值类型 @@ -202,7 +199,6 @@ Swift 默认字符串拷贝的方式保证了在函数/方法中传递的是字 在实际编译时,Swift 编译器会优化字符串的使用,使实际的复制只发生在绝对必要的情况下,这意味着您将字符串作为值类型的同时可以获得极高的性能。 - ## 使用字符 @@ -317,7 +313,6 @@ let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)" > 注意: > 插值字符串中写在括号中的表达式不能包含非转义反斜杠 (`\`),并且不能包含回车或换行符。不过,插值字符串可以包含其他字面量。 - ## Unicode @@ -325,7 +320,6 @@ let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)" 它使您可以用标准格式表示来自任意语言几乎所有的字符,并能够对文本文件或网页这样的外部资源中的字符进行读写操作。 Swift 的`String`和`Character`类型是完全兼容 Unicode 标准的。 - ### Unicode 标量 @@ -339,7 +333,6 @@ Unicode 标量是对应字符或者修饰符的唯一的21位数字,例如`U+0 - ### 可扩展的字形群集 @@ -361,7 +354,6 @@ let combinedEAcute: Character = "\u{65}\u{301}" // e 后面加上 ́ 例如,来自朝鲜语字母表的韩语音节能表示为组合或分解的有序排列。 在 Swift 都会表示为同一个单一的`Character`值: - ```swift let precomposed: Character = "\u{D55C}" // 한 let decomposed: Character = "\u{1112}\u{1161}\u{11AB}" // ᄒ, ᅡ, ᆫ @@ -377,7 +369,6 @@ let enclosedEAcute: Character = "\u{E9}\u{20DD}" 地域性指示符号的 Unicode 标量可以组合成一个单一的`Character`值,例如`REGIONAL INDICATOR SYMBOL LETTER U`(`U+1F1FA`)和`REGIONAL INDICATOR SYMBOL LETTER S`(`U+1F1F8`): - ```swift let regionalIndicatorForUS: Character = "\u{1F1FA}\u{1F1F8}" // regionalIndicatorForUS 是 🇺🇸 @@ -414,7 +405,6 @@ print("the number of characters in \(word) is \(word.count)") > > 另外需要注意的是通过`count`属性返回的字符数量并不总是与包含相同字符的`NSString`的`length`属性相同。`NSString`的`length`属性是利用 UTF-16 表示的十六位代码单元数字,而不是 Unicode 可扩展的字符群集。 - ## 访问和修改字符串 @@ -569,7 +559,6 @@ if latinCapitalLetterA != cyrillicCapitalLetterA { > 注意: > 在 Swift 中,字符串和字符并不区分地域(not locale-sensitive)。 - ### 前缀/后缀相等 @@ -625,7 +614,6 @@ print("\(mansionCount) mansion scenes; \(cellCount) cell scenes") > 注意: > `hasPrefix(_:)`和`hasSuffix(_:)`方法都是在每个字符串中逐字符比较其可扩展的字符群集是否标准相等,详细描述在[字符串/字符相等](#string_and_character_equality)。 - ## 字符串的 Unicode 表示形式 @@ -690,7 +678,6 @@ let dogString = "Dog‼🐶" - ```swift for codeUnit in dogString.utf8 { print("\(codeUnit) ", terminator: "") @@ -703,7 +690,6 @@ print("") 接下来的三个10进制`codeUnit`值 (`226`, `128`, `188`) 是`DOUBLE EXCLAMATION MARK`的3字节 UTF-8 表示。 最后的四个`codeUnit`值 (`240`, `159`, `144`, `182`) 是`DOG FACE`的4字节 UTF-8 表示。 - ### UTF-16 表示 @@ -739,7 +725,6 @@ print("") - ```swift for codeUnit in dogString.utf16 { print("\(codeUnit) ", terminator: "") @@ -764,7 +749,6 @@ print("") 每一个`UnicodeScalar`拥有一个`value`属性,可以返回对应的21位数值,用`UInt32`来表示: - @@ -792,7 +776,6 @@ print("")
    Character
    - ```swift for scalar in dogString.unicodeScalars { print("\(scalar.value) ", terminator: "") diff --git a/source/chapter2/04_Collection_Types.md b/source/chapter2/04_Collection_Types.md index 1c6f3044..2fcd9fd3 100755 --- a/source/chapter2/04_Collection_Types.md +++ b/source/chapter2/04_Collection_Types.md @@ -18,7 +18,6 @@ > 校对:[shanks](http://codebuild.me) ,2016-10-09 > 3.0.1,shanks,2016-11-12 - 本页包含内容: - [集合的可变性](#mutability_of_collections) @@ -198,7 +197,6 @@ shoppingList[4...6] = ["Bananas", "Apples"] > 注意: 不可以用下标访问的形式去在数组尾部添加新项。 - 调用数组的`insert(_:at:)`方法来在某个具体索引值之前添加数据项: ```swift diff --git a/source/chapter2/05_Control_Flow.md b/source/chapter2/05_Control_Flow.md index 932f9c59..0bd2b249 100755 --- a/source/chapter2/05_Control_Flow.md +++ b/source/chapter2/05_Control_Flow.md @@ -211,7 +211,6 @@ print("Game over!") `while` 循环比较适合本例中的这种情况,因为在 `while` 循环开始时,我们并不知道游戏要跑多久,只有在达成指定条件时循环才会结束。 - ### Repeat-While @@ -344,7 +343,6 @@ default: } ``` - `switch`语句由*多个 case* 构成,每个由`case`关键字开始。为了匹配某些更特定的值,Swift 提供了几种方法来进行更复杂的模式匹配,这些模式将在本节的稍后部分提到。 与`if`语句类似,每一个 case 都是代码执行的一条分支。`switch`语句会决定哪一条分支应该被执行,这个流程被称作根据给定的值*切换(switching)*。 @@ -353,7 +351,6 @@ default: 下面的例子使用`switch`语句来匹配一个名为`someCharacter`的小写字符: - ```swift let someCharacter: Character = "z" switch someCharacter { @@ -370,7 +367,6 @@ default: 在这个例子中,第一个 case 分支用于匹配第一个英文字母`a`,第二个 case 分支用于匹配最后一个字母`z`。 因为`switch`语句必须有一个case分支用于覆盖所有可能的字符,而不仅仅是所有的英文字母,所以switch语句使用`default`分支来匹配除了`a`和`z`外的所有值,这个分支保证了swith语句的完备性。 - #### 不存在隐式的贯穿 @@ -440,8 +436,6 @@ print("There are \(naturalCount) \(countedThings).") 在上例中,`approximateCount`在一个`switch`声明中被评估。每一个`case`都与之进行比较。因为`approximateCount`落在了 12 到 100 的区间,所以`naturalCount`等于`"dozens of"`值,并且此后的执行跳出了`switch`语句。 - - #### 元组 @@ -472,7 +466,6 @@ default: 不像 C 语言,Swift 允许多个 case 匹配同一个值。实际上,在这个例子中,点(0, 0)可以匹配所有_四个 case_。但是,如果存在多个匹配,那么只会执行第一个被匹配到的 case 分支。考虑点(0, 0)会首先匹配`case (0, 0)`,因此剩下的能够匹配的分支都会被忽视掉。 - #### 值绑定(Value Bindings) @@ -568,7 +561,6 @@ default: 上面的case有两个模式:`(let distance, 0)`匹配了在x轴上的值,`(0, let distance)`匹配了在y轴上的值。两个模式都绑定了`distance`,并且`distance`在两种模式下,都是整型——这意味着分支体内的代码,只要case匹配,都可以获取到`distance`值 - ## 控制转移语句 @@ -760,7 +752,6 @@ print("Game over!") 像`if`语句一样,`guard`的执行取决于一个表达式的布尔值。我们可以使用`guard`语句来要求条件必须为真时,以执行`guard`语句后的代码。不同于`if`语句,一个`guard`语句总是有一个`else`从句,如果条件不为真则执行`else`从句中的代码。 - ```swift func greet(person: [String: String]) { guard let name = person["name"] else { diff --git a/source/chapter2/06_Functions.md b/source/chapter2/06_Functions.md index cb46f36d..b76f0ef2 100755 --- a/source/chapter2/06_Functions.md +++ b/source/chapter2/06_Functions.md @@ -30,7 +30,6 @@ - [函数类型](#Function_Types) - [嵌套函数](#Nested_Functions) - *函数*是一段完成特定任务的独立代码片段。你可以通过给函数命名来标识某个函数的功能,这个名字可以被用来在需要的时候"调用"这个函数来完成它的任务。 Swift 统一的函数语法非常的灵活,可以用来表示任何函数,包括从最简单的没有参数名字的 C 风格函数,到复杂的带局部和外部参数名的 Objective-C 风格函数。参数可以提供默认值,以简化函数调用。参数也可以既当做传入参数,也当做传出参数,也就是说,一旦函数执行结束,传入的参数值将被修改。 @@ -44,10 +43,8 @@ Swift 统一的函数语法非常的灵活,可以用来表示任何函数, 每个函数有个*函数名*,用来描述函数执行的任务。要使用一个函数时,用函数名来“调用”这个函数,并传给它匹配的输入值(称作 *实参* )。函数的实参必须与函数参数表里参数的顺序一致。 - 下面例子中的函数的名字是`greet(person:)`,之所以叫这个名字,是因为这个函数用一个人的名字当做输入,并返回向这个人问候的语句。为了完成这个任务,你需要定义一个输入参数——一个叫做 `person` 的 `String` 值,和一个包含给这个人问候语的 `String` 类型的返回值: - ```swift func greet(person: String) -> String { let greeting = "Hello, " + person + "!" @@ -71,7 +68,6 @@ print(greet(person: "Brian")) >注意 `print(_:separator:terminator:)` 函数的第一个参数并没有设置一个标签,而其他的参数因为已经有了默认值,因此是可选的。关于这些函数语法上的变化详见下方关于 函数参数标签和参数名 以及 默认参数值。 - 在 `greet(person:)` 的函数体中,先定义了一个新的名为 `greeting` 的 `String` 常量,同时,把对 `personName` 的问候消息赋值给了 `greeting` 。然后用 `return` 关键字把这个问候返回出去。一旦 `return greeting` 被调用,该函数结束它的执行并返回 `greeting` 的当前值。 你可以用不同的输入值多次调用 `greet(person:)`。上面的例子展示的是用`"Anna"`和`"Brian"`调用的结果,该函数分别返回了不同的结果。 @@ -145,7 +141,6 @@ greet(person: "Dave") >注意 严格上来说,虽然没有返回值被定义,`greet(person:)` 函数依然返回了值。没有定义返回类型的函数会返回一个特殊的`Void`值。它其实是一个空的元组(tuple),没有任何元素,可以写成()。 - 被调用时,一个函数的返回值可以被忽略: ```swift @@ -167,7 +162,6 @@ printWithoutCounting(string: "hello, world") >注意: 返回值可以被忽略,但定义了有返回值的函数必须返回一个值,如果在函数定义底部没有返回任何值,将导致编译时错误(compile-time error)。 - ### 多重返回值函数 @@ -212,12 +206,10 @@ print("min is \(bounds.min) and max is \(bounds.max)") >注意 可选元组类型如 `(Int, Int)?` 与元组包含可选类型如 `(Int?, Int?)` 是不同的.可选的元组类型,整个元组是可选的,而不只是元组中的每个元素值。 - 前面的 `minMax(array:)` 函数返回了一个包含两个 `Int` 值的元组。但是函数不会对传入的数组执行任何安全检查,如果 `array` 参数是一个空数组,如上定义的 `minMax(array:)` 在试图访问 `array[0]` 时会触发一个运行时错误(runtime error)。 为了安全地处理这个“空数组”问题,将 `minMax(array:)` 函数改写为使用可选元组返回类型,并且当数组为空时返回 `nil`: - ```swift func minMax(array: [Int]) -> (min: Int, max: Int)? { if array.isEmpty { return nil } @@ -243,7 +235,6 @@ if let bounds = minMax(array: [8, -6, 2, 109, 3, 71]) { // 打印 "min is -6 and max is 109" ``` - ## 函数参数标签和参数名称 @@ -348,7 +339,6 @@ arithmeticMean(3, 8.25, 18.75) >注意 输入输出参数不能有默认值,而且可变参数不能用 `inout` 标记。 - 下例中,`swapTwoInts(_:_:)` 函数有两个分别叫做 `a` 和 `b` 的输入输出参数: ```swift @@ -376,7 +366,6 @@ print("someInt is now \(someInt), and anotherInt is now \(anotherInt)") >注意: 输入输出参数和返回值是不一样的。上面的 `swapTwoInts` 函数并没有定义任何返回值,但仍然修改了 `someInt` 和 `anotherInt` 的值。输入输出参数是函数对函数体外产生影响的另一种方式。 - ## 函数类型 @@ -431,7 +420,6 @@ print("Result: \(mathFunction(2, 3))") 有相同匹配类型的不同函数可以被赋值给同一个变量,就像非函数类型的变量一样: - ```swift mathFunction = multiplyTwoInts print("Result: \(mathFunction(2, 3))") diff --git a/source/chapter2/07_Closures.md b/source/chapter2/07_Closures.md index 3ffac397..577a0762 100755 --- a/source/chapter2/07_Closures.md +++ b/source/chapter2/07_Closures.md @@ -54,7 +54,6 @@ Swift 的闭包表达式拥有简洁的风格,并鼓励在常见场景中进 ## 闭包表达式 - [嵌套函数](./06_Functions.html#nested_function)是一个在较复杂函数中方便进行命名和定义自包含代码模块的方式。当然,有时候编写小巧的没有完整定义和命名的类函数结构也是很有用处的,尤其是在你处理一些函数并需要将另外一些函数作为该函数的参数时。 *闭包表达式*是一种利用简洁语法构建内联闭包的方式。闭包表达式提供了一些语法优化,使得撰写闭包变得简单明了。下面闭包表达式的例子通过使用几次迭代展示了 `sorted(by:)` 方法定义和语法优化的方式。每一次迭代都用更简洁的方式描述了相同的功能。 @@ -360,7 +359,6 @@ func someFunctionWithEscapingClosure(completionHandler: @escaping () -> Void) { 将一个闭包标记为 `@escaping` 意味着你必须在闭包中显式地引用 `self`。比如说,在下面的代码中,传递到 `someFunctionWithEscapingClosure(_:)` 中的闭包是一个逃逸闭包,这意味着它需要显式地引用 `self`。相对的,传递到 `someFunctionWithNonescapingClosure(_:)` 中的闭包是一个非逃逸闭包,这意味着它可以隐式引用 `self`。 - ```swift func someFunctionWithNonescapingClosure(closure: () -> Void) { closure() diff --git a/source/chapter2/08_Enumerations.md b/source/chapter2/08_Enumerations.md index 344424e7..50657304 100755 --- a/source/chapter2/08_Enumerations.md +++ b/source/chapter2/08_Enumerations.md @@ -15,7 +15,6 @@ > 2.2 > 翻译+校对:[SketchK](https://github.com/SketchK) 2016-05-13 - > 3.0 > 翻译+校对:[shanks](https://codebuild.me) 2016-09-24 > 3.0.1,shanks,2016-11-12 @@ -220,7 +219,6 @@ enum ASCIIControlCharacter: Character { 枚举类型`ASCIIControlCharacter`的原始值类型被定义为`Character`,并设置了一些比较常见的 ASCII 控制字符。`Character`的描述详见[字符串和字符](./03_Strings_and_Characters.html)部分。 - 原始值可以是字符串,字符,或者任意整型值或浮点型值。每个原始值在枚举声明中必须是唯一的。 > 注意 @@ -304,7 +302,6 @@ if let somePlanet = Planet(rawValue: positionToFind) { ## 递归枚举 - *递归枚举*是一种枚举类型,它有一个或多个枚举成员使用该枚举类型的实例作为关联值。使用递归枚举时,编译器会插入一个间接层。你可以在枚举成员前加上`indirect`来表示该成员可递归。 例如,下面的例子中,枚举类型存储了简单的算术表达式: diff --git a/source/chapter2/09_Classes_and_Structures.md b/source/chapter2/09_Classes_and_Structures.md index 4815ba2a..458d2202 100755 --- a/source/chapter2/09_Classes_and_Structures.md +++ b/source/chapter2/09_Classes_and_Structures.md @@ -26,7 +26,6 @@ - [类和结构体的选择](#choosing_between_classes_and_structures) - [字符串、数组、和字典类型的赋值与复制行为](#assignment_and_copy_behavior_for_strings_arrays_and_dictionaries) - *类*和*结构体*是人们构建代码所用的一种通用且灵活的构造体。我们可以使用完全相同的语法规则来为类和结构体定义属性(常量、变量)和添加方法,从而扩展类和结构体的功能。 与其他编程语言所不同的是,Swift 并不要求你为自定义类和结构去创建独立的接口和实现文件。你所要做的是在一个单一文件中定义一个类或者结构体,系统将会自动生成面向其它代码的外部接口。 diff --git a/source/chapter2/10_Properties.md b/source/chapter2/10_Properties.md index 2b09a390..d0b0e909 100755 --- a/source/chapter2/10_Properties.md +++ b/source/chapter2/10_Properties.md @@ -5,16 +5,13 @@ > 翻译:[shinyzhu](https://github.com/shinyzhu) > 校对:[pp-prog](https://github.com/pp-prog) [yangsiy](https://github.com/yangsiy) - > 2.0 > 翻译+校对:[yangsiy](https://github.com/yangsiy) - > 2.1 > 翻译:[buginux](https://github.com/buginux) > 校对:[shanks](http://codebuild.me),2015-10-29 - > 2.2 > 翻译:[saitjr](https://github.com/saitjr),2016-04-11,[SketchK](https://github.com/SketchK) 2016-05-13 > @@ -240,7 +237,6 @@ print("the volume of fourByFiveByTwo is \(fourByFiveByTwo.volume)") 可以为除了延迟存储属性之外的其他存储属性添加属性观察器,也可以通过重写属性的方式为继承的属性(包括存储属性和计算属性)添加属性观察器。你不必为非重写的计算属性添加属性观察器,因为可以通过它的 setter 直接监控和响应值的变化。 属性重写请参考[重写](./13_Inheritance.html#overriding)。 - 可以为属性添加如下的一个或全部观察器: - `willSet` 在新的值被设置之前调用 diff --git a/source/chapter2/11_Methods.md b/source/chapter2/11_Methods.md index b8e0605a..7ee82188 100755 --- a/source/chapter2/11_Methods.md +++ b/source/chapter2/11_Methods.md @@ -73,7 +73,6 @@ counter.reset() 函数参数可以同时有一个局部名称(在函数体内部使用)和一个外部名称(在调用函数时使用),详情参见[指定外部参数名](./06_Functions.html#specifying_external_parameter_names)。方法参数也一样,因为方法就是函数,只是这个函数与某个类型相关联了。 - ### self 属性 diff --git a/source/chapter2/12_Subscripts.md b/source/chapter2/12_Subscripts.md index 80532797..c078a76a 100755 --- a/source/chapter2/12_Subscripts.md +++ b/source/chapter2/12_Subscripts.md @@ -6,18 +6,17 @@ > 校对:[zq54zquan](https://github.com/zq54zquan) > 2.0 -> 翻译+校对:[shanks](http://codebuild.me) - +> 翻译+校对:[shanks](http://codebuild.me) + > 2.1 -> 翻译+校对:[shanks](http://codebuild.me),[Realank](https://github.com/Realank) - -> 2.2 -> 校对:[SketchK](https://github.com/SketchK) 2016-05-13 +> 翻译+校对:[shanks](http://codebuild.me),[Realank](https://github.com/Realank) + +> 2.2 +> 校对:[SketchK](https://github.com/SketchK) 2016-05-13 > 3.0.1,shanks,2016-11-13 - -> 4.0 + +> 4.0 > 校对:[kemchenj](https://kemchenj.github.io/) 2017-09-21 - 本页包含内容: diff --git a/source/chapter2/14_Initialization.md b/source/chapter2/14_Initialization.md index ce6f28bd..3496255e 100755 --- a/source/chapter2/14_Initialization.md +++ b/source/chapter2/14_Initialization.md @@ -34,7 +34,6 @@ - [必要构造器](#required_initializers) - [通过闭包或函数设置属性的默认值](#setting_a_default_property_value_with_a_closure_or_function) - *构造过程*是使用类、结构体或枚举类型的实例之前的准备过程。在新实例可用前必须执行这个过程,具体操作包括设置实例中每个存储型属性的初始值和执行其他必须的设置或初始化工作。 通过定义*构造器*来实现构造过程,就像用来创建特定类型新实例的特殊方法。与 Objective-C 中的构造器不同,Swift 的构造器无需返回值,它们的主要任务是保证新实例在第一次使用前完成正确的初始化。 @@ -569,7 +568,6 @@ print("Bicycle: \(bicycle.description)") > 注意 子类可以在初始化时修改继承来的变量属性,但是不能修改继承来的常量属性。 - ### 构造器的自动继承 @@ -864,7 +862,6 @@ if unknownUnit == nil { 下面这个例子,定义了一个名为`CartItem`的`Product`类的子类。这个类建立了一个在线购物车中的物品的模型,它有一个名为`quantity`的常量存储型属性,并确保该属性的值至少为`1`: - ```swift class Product { let name: String diff --git a/source/chapter2/18_Error_Handling.md b/source/chapter2/18_Error_Handling.md index 5536bb8b..746d3846 100755 --- a/source/chapter2/18_Error_Handling.md +++ b/source/chapter2/18_Error_Handling.md @@ -151,7 +151,6 @@ struct PurchasedSnack { } ``` - ### 用 Do-Catch 处理错误 可以使用一个`do-catch`语句运行一段闭包代码来处理错误。如果在`do`子句中的代码抛出了一个错误,这个错误会与`catch`子句做匹配,从而决定哪条子句能处理它。 diff --git a/source/chapter2/19_Type_Casting.md b/source/chapter2/19_Type_Casting.md index 22276e14..0601a5bf 100644 --- a/source/chapter2/19_Type_Casting.md +++ b/source/chapter2/19_Type_Casting.md @@ -25,7 +25,6 @@ - [向下转型](#downcasting) - [`Any` 和 `AnyObject` 的类型转换](#type_casting_for_any_and_anyobject) - _类型转换_ 可以判断实例的类型,也可以将实例看做是其父类或者子类的实例。 类型转换在 Swift 中使用 `is` 和 `as` 操作符实现。这两个操作符提供了一种简单达意的方式去检查值的类型或者转换它的类型。 diff --git a/source/chapter2/21_Extensions.md b/source/chapter2/21_Extensions.md index fef872d0..dbc1d3ca 100644 --- a/source/chapter2/21_Extensions.md +++ b/source/chapter2/21_Extensions.md @@ -285,7 +285,6 @@ extension Int { 现在,这个嵌套枚举可以和任意 `Int` 值一起使用了: - ```swift func printIntegerKinds(_ numbers: [Int]) { for number in numbers { diff --git a/source/chapter2/22_Protocols.md b/source/chapter2/22_Protocols.md index 154cc205..c3567ac6 100644 --- a/source/chapter2/22_Protocols.md +++ b/source/chapter2/22_Protocols.md @@ -758,7 +758,6 @@ for object in objects { 使用可选要求时(例如,可选的方法或者属性),它们的类型会自动变成可选的。比如,一个类型为 `(Int) -> String` 的方法会变成 `((Int) -> String)?`。需要注意的是整个函数类型是可选的,而不是函数的返回值。 - 协议中的可选要求可通过可选链式调用来使用,因为遵循协议的类型可能没有实现这些可选要求。类似 `someOptionalMethod?(someArgument)` 这样,你可以在可选方法名称后加上 `?` 来调用可选方法。详细内容可在[可选链式调用](./17_Optional_Chaining.html)章节中查看。 下面的例子定义了一个名为 `Counter` 的用于整数计数的类,它使用外部的数据源来提供每次的增量。数据源由 `CounterDataSource` 协议定义,包含两个可选要求: @@ -797,7 +796,6 @@ class Counter { 这里使用了两层可选链式调用。首先,由于 `dataSource` 可能为 `nil`,因此在 `dataSource` 后边加上了 `?`,以此表明只在 `dataSource` 非空时才去调用 `increment(forCount:)` 方法。其次,即使 `dataSource` 存在,也无法保证其是否实现了 `increment(forCount:)` 方法,因为这个方法是可选的。因此,`increment(forCount:)` 方法同样使用可选链式调用进行调用,只有在该方法被实现的情况下才能调用它,所以在 `increment(forCount:)` 方法后边也加上了 `?`。 - 调用 `increment(forCount:)` 方法在上述两种情形下都有可能失败,所以返回值为 `Int?` 类型。虽然在 `CounterDataSource` 协议中,`increment(forCount:)` 的返回值类型是非可选 `Int`。另外,即使这里使用了两层可选链式调用,最后的返回结果依旧是单层的可选类型。关于这一点的更多信息,请查阅[连接多层可选链式调用](./17_Optional_Chaining) 在调用 `increment(forCount:)` 方法后,`Int?` 型的返回值通过可选绑定解包并赋值给常量 `amount`。如果可选值确实包含一个数值,也就是说,数据源和方法都存在,数据源方法返回了一个有效值。之后便将解包后的 `amount` 加到 `count` 上,增量操作完成。 diff --git a/source/chapter2/25_Advanced_Operators.md b/source/chapter2/25_Advanced_Operators.md index 69959a36..5bbe8bd3 100644 --- a/source/chapter2/25_Advanced_Operators.md +++ b/source/chapter2/25_Advanced_Operators.md @@ -46,7 +46,6 @@ Swift 支持 C 语言中的全部位运算符,接下来会一一介绍。 *按位取反运算符(`~`)*可以对一个数值的全部比特位进行取反: - ![Art/bitwiseNOT_2x.png](https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/bitwiseNOT_2x.png) 按位取反运算符是一个前缀运算符,需要直接放在运算的数之前,并且它们之间不能添加任何空格: @@ -397,7 +396,6 @@ original += vectorToAdd // original 的值现在为 (4.0, 6.0) ``` - > 注意 > 不能对默认的赋值运算符(`=`)进行重载。只有组合赋值运算符可以被重载。同样地,也无法对三目条件运算符 (`a ? b : c`) 进行重载。 @@ -453,7 +451,6 @@ extension Vector2D { } } - var toBeDoubled = Vector2D(x: 1.0, y: 4.0) let afterDoubling = +++toBeDoubled // toBeDoubled 现在的值为 (2.0, 8.0) diff --git a/source/chapter3/02_Lexical_Structure.md b/source/chapter3/02_Lexical_Structure.md index 3f7ee53b..9ec8669c 100755 --- a/source/chapter3/02_Lexical_Structure.md +++ b/source/chapter3/02_Lexical_Structure.md @@ -5,22 +5,15 @@ > 翻译:[superkam](https://github.com/superkam) > 校对:[numbbbbb](https://github.com/numbbbbb) - - > 2.0 > 翻译+校对:[buginux](https://github.com/buginux) - - > 2.1 > 翻译:[mmoaay](https://github.com/mmoaay) - - > 2.2 > 翻译+校对:[星夜暮晨](https://github.com/semperidem),2016-04-06 - 本页包含内容: - [空白与注释](#whitespace_and_comments) diff --git a/source/chapter3/04_Expressions.md b/source/chapter3/04_Expressions.md index 26258390..912b0eff 100644 --- a/source/chapter3/04_Expressions.md +++ b/source/chapter3/04_Expressions.md @@ -579,7 +579,6 @@ let anotherSelector = #selector(SomeClass.doSomething(_:) as (SomeClass) -> (Str > *选择器表达式* → __#selector__ **(** [*getter:表达式*](#expression) **)** > *选择器表达式* → __#selector__ **(** [*setter:表达式*](#expression) **)** - ## 后缀表达式 diff --git a/source/chapter3/05_Declarations.md b/source/chapter3/05_Declarations.md index e87a5f55..7671d010 100755 --- a/source/chapter3/05_Declarations.md +++ b/source/chapter3/05_Declarations.md @@ -579,9 +579,6 @@ Swift定义了`Never`类型,它表示函数或者方法不会返回给它的 > > *默认参数子句* → **=** [*表达式*](04_Expressions.md#expression) - - - ## 枚举声明 @@ -1211,7 +1208,6 @@ postfix operator 运算符名称 {} > *中缀运算符组* → [*优先级组名称*](#precedence-group-name) - ## 优先级组声明 @@ -1263,7 +1259,6 @@ Swift定义了大量的优先级组来与标准库的运算符配合使用,例 > *优先级组名称* →[*标识符*](02_Lexical_Structure.md#identifier) - ## 声明修饰符 声明修饰符都是关键字或上下文相关的关键字,可以修改一个声明的行为或者含义。可以在声明的特性(如果存在)和引入该声明的关键字之间,利用声明修饰符的关键字或上下文相关的关键字指定一个声明修饰符。 diff --git a/source/chapter3/08_Generic_Parameters_and_Arguments.md b/source/chapter3/08_Generic_Parameters_and_Arguments.md index 84e92707..0f8d459c 100755 --- a/source/chapter3/08_Generic_Parameters_and_Arguments.md +++ b/source/chapter3/08_Generic_Parameters_and_Arguments.md @@ -36,7 +36,6 @@ 约束用于指明该类型形参继承自某个类或者符合某个协议或协议组合。例如,在下面的泛型函数中,泛型形参 `T: Comparable` 表示任何用于替代类型形参 `T` 的类型实参必须满足 `Comparable` 协议。 - ```swift func simpleMax(_ x: T, _ y: T) -> T { if x < y { @@ -94,7 +93,6 @@ simpleMax(3.14159, 2.71828) // T 被推断为 Double 类型 > *同类型约束* → [*类型标识符*](03_Types.html#type-identifier) **==** [*类型*](03_Types.html#type) - ## 泛型实参子句 diff --git a/source/chapter3/09_Summary_of_the_Grammar.md b/source/chapter3/09_Summary_of_the_Grammar.md index 4377da55..ac7c3688 100755 --- a/source/chapter3/09_Summary_of_the_Grammar.md +++ b/source/chapter3/09_Summary_of_the_Grammar.md @@ -101,7 +101,6 @@ > *else从句(Clause)* → **else** [*代码块*](../chapter3/05_Declarations.html#code_block) | **else** [*if语句*](../chapter3/10_Statements.html#if_statement) - >Guard 语句语法 >*guard语句* → **guard** [*条件从句*](TODO) **else** [*代码块*](TODO) @@ -198,8 +197,6 @@ >*catch-clauses* → **catch** [*模式(pattern)*](TODO) _可选_ [*where-clause*](TODO) _可选_ [*代码块(code-block)*](TODO) _可选_ - - ## 泛型参数 @@ -508,7 +505,6 @@ > 可选模式语法 > *可选模式* → [*识别符模式*](TODO) **?** - > 类型转换模式语法 @@ -554,7 +550,6 @@ > try表达式语法 > *try-operator* → **try** | **try !** - > 二元表达式语法 @@ -585,8 +580,6 @@ > *类型转换运算符* → **as !** [*类型*](../chapter3/03_Types.html#type) - - > 主表达式语法 diff --git a/source/chapter3/10_Statements.md b/source/chapter3/10_Statements.md index 3b019dbb..57ccb9d9 100755 --- a/source/chapter3/10_Statements.md +++ b/source/chapter3/10_Statements.md @@ -134,7 +134,6 @@ while 条件 { > *可选绑定条件* → **let** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) | **var** [*模式*](07_Patterns.md#pattern) [*构造器*](05_Declarations.md#initializer) - ### Repeat-While 语句 diff --git a/source/chapter4/01_Access_Control.md b/source/chapter4/01_Access_Control.md index 60893521..7ce1b92f 100644 --- a/source/chapter4/01_Access_Control.md +++ b/source/chapter4/01_Access_Control.md @@ -11,7 +11,6 @@ > 小明说哇靠学姐你还会妖法...... - Swift语言从Xcode 6 beta 5版本起,加入了对权限控制(Access Control)的支持。其实权限控制和小明的物品一样,你可以设定水壶是只有自己能用,还是只有宿舍里的人能用,还是全校都可以用。 从此以后,你可以好像神盾局局长一样,完全掌控自己的代码块的”保密级别“,哪些是只能在本文件引用,哪些能用在整个项目里,你还可以发挥大爱精神,把它开源成只要导入你的框架,大家都可以使用的API。 @@ -30,7 +29,6 @@ Swift语言从Xcode 6 beta 5版本起,加入了对权限控制(Access Contro 标记为public的代码块一般用来建立API,这是最开放的权限,使得任何人只要导入这个模块,都可以访问使用。 - 如果要把所有的爱加上一个期限,噢不,是给所有的代码块都标记上权限,不累死才怪。还好swift里面所有代码实体的默认权限,都是最常用的internal。所以当你开发自己的App时,可能完全不用管权限控制的事情。 但当你需要写一个公开API的时候,就必须对里面的代码块进行“隐身对其可见”的public标记,要么其他人是用不到的。 diff --git a/source/chapter4/02_Type_Custom.md b/source/chapter4/02_Type_Custom.md index 8affad31..76a0526d 100644 --- a/source/chapter4/02_Type_Custom.md +++ b/source/chapter4/02_Type_Custom.md @@ -86,7 +86,6 @@ enum OCBool{ case ocFalse } - extension OCBool: BooleanLiteralConvertible{ static func convertFromBooleanLiteral( value: Bool) ->OCBool{ return value ? ocTrue : ocFalse @@ -142,7 +141,6 @@ enum OCBool{ case ocFalse } - extension OCBool: BooleanLiteralConvertible{ static func convertFromBooleanLiteral( value: Bool) ->OCBool{ return value ? ocTrue : ocFalse @@ -163,7 +161,6 @@ extension OCBool: LogicValue{ } } - var isSuccess:OCBool = true if isSuccess { @@ -209,7 +206,6 @@ extension OCBool{ var mmResult: Bool = true var ocResult:OCBool = OCBool(mmResult) - if ocResult { println( "老码没钱,郭美美请你吃火锅!") } @@ -280,7 +276,6 @@ func &= (inout left:OCBool, right:OCBool ){ left = left & right } - var isHasMoney:OCBool = true var isHasWife:OCBool = true var isHasHealty:OCBool = true @@ -301,6 +296,4 @@ if (isHasMoney | isHasHealty) & isHasHealty{ 好了,到这里就到这里了,窗外的雷声叫醒了老码,现在应该去吃饭了,以上老码给大家展示了如果制造一个自己的类型,记得老码的示例是在Xcode6 Beta4下测试的,至于Beta5的改变还没有涉及,小伙伴们要好生练习,以后各种自定类型都是基于这个思想。还有这个章节不是老码的原创,老码认真的阅读了苹果的官方博客,且自己的练习总结,如果小伙伴们费了吃奶的劲还是看不懂,请找度娘谷歌,还是看不懂请到老码官方微博:http://weibo.com/u/5241713117咆哮。 - - 本文由翻译自Apple Swift Blog :https://developer.apple.com/swift/blog/?id=8 diff --git a/source/chapter4/03_Ballons.md b/source/chapter4/03_Ballons.md index 1c749ebe..b6a77d97 100644 --- a/source/chapter4/03_Ballons.md +++ b/source/chapter4/03_Ballons.md @@ -5,7 +5,6 @@ ![Ballon playground](https://devimages.apple.com.edgekey.net/swift/images/swift-screenshot.jpg) - 很多小伙伴说,对WWDC上介绍Swift语言时,演示的那个“大炮打气球”的Ballons项目很感兴趣。 Ballons不但展现了playgrounds许多很赞的特性,还让我们看到写代码的过程,原来可以这么互动,这么好玩。 @@ -14,5 +13,4 @@ Ballons不但展现了playgrounds许多很赞的特性,还让我们看到写 这个playground文件用到了SpriteKit的新特性,因此需要最新beta版本的Xcode 6和Yosemite系统来支持它运行。 - 本文由翻译自Apple Swift Blog的博文:[Ballons](https://developer.apple.com/swift/blog/?id=9) diff --git a/source/chapter4/05_Value_and_Reference_Types.md b/source/chapter4/05_Value_and_Reference_Types.md index d38b11b0..0179951f 100644 --- a/source/chapter4/05_Value_and_Reference_Types.md +++ b/source/chapter4/05_Value_and_Reference_Types.md @@ -10,7 +10,6 @@ - [Mutation(修改)在安全中扮演的角色](#act-in=mutation) - [如何选择类型](#how-to-choose) - ### Swift里面的类型分为两种: * **值类型(Value Types)**:每个实例都保留了一分独有的数据拷贝,一般以结构体 `(struct)`、`枚举(enum)` 或者`元组(tuple)`的形式出现。 diff --git a/source/chapter4/07_Optional_Case_Study.md b/source/chapter4/07_Optional_Case_Study.md index 40c78cff..4576d555 100644 --- a/source/chapter4/07_Optional_Case_Study.md +++ b/source/chapter4/07_Optional_Case_Study.md @@ -13,7 +13,6 @@ 可选类型是Swift中新引入的,功能很强大。在这篇博文里讨论的,是在Swift里,如何通过可选类型来保证强类型的安全性。作为例子,我们来创建一个Objective-C API的Swift版本,但实际上Swift本身并不需要这样的API。 - #### 为Dictionary增加objectsForKeys函数 @@ -31,7 +30,6 @@ extension Dictionary{ 以上就是我们实现的Swift版本,这个和Objective-C版本有很大区别。在Swift中,因为其强类型的原因限制了返回的结果数组只能包含单一类型的元素,所以我们不能放```NSNull```在字符串数组中,但是,Swift有更好的选择,我们可以返回一个可选类型数据。我们所有的值都封包在可选类型中,而不是```NSNull```, 我们只用```nil```就可以了。 - ```swift extension Dictionary{ func valuesForKeys(keys: [Key]) -> [Value?] { diff --git a/source/v1.0.md b/source/v1.0.md index ee97b3f0..75d5ba77 100644 --- a/source/v1.0.md +++ b/source/v1.0.md @@ -8,7 +8,6 @@ > 关于文档中翻译错误,逻辑错误以及疑难问题答疑,请关注["@老码团队"](http://weibo.com/u/5241713117 )官方微博,会有技术人员统一收集答疑 - # The Swift Programming Language 中文版#### ###这一次,让中国和世界同步