3 Commits

Author SHA1 Message Date
47598b3c8e Patch 1 (#927)
* Update contributors.md

* 校对: chapter2/03_Strings_and_Characters 方法名变化 (#921)

index(of:) 已更名为: firstIndex(of:)

* Update 01_The_Basics.md

* fix invalid url (#923)

* test gitbook anchor

* Revert "test gitbook anchor"

This reverts commit e82cea3866.

* Update 21_Protocols.md (#924)

* Update 25_Access_Control.md (#925)

* Update 02_version_compatibility.md
2019-05-03 18:58:57 -05:00
1c973d61a1 更新电子书封面和introduce
Signed-off-by: Harry Twan <gua@desgard.com>
2019-04-12 09:55:43 +08:00
7a53af48c1 适配 gitbook
Signed-off-by: Harry Twan <gua@desgard.com>
2019-04-12 08:31:57 +08:00
12 changed files with 206 additions and 69 deletions

4
SUMMARY.md Normal file
View File

@ -0,0 +1,4 @@
# Summary
* [Introduction](README.md)

4
source/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
_book
*.pdf
*.epub
*.mobi

View File

@ -1,22 +1,149 @@
> 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 官方文档中文翻译工作由[numbbbbb](https://github.com/numbbbbb)发起并主导,该工作已经得到了苹果官方的认可。下面是各个版本官方文档翻译和校对工作的主要贡献者,排名不分先后。
## Swift 5.x 主要贡献者
- [Adolf-L](https://github.com/Adolf-L)
- [BigNerdCoding](https://github.com/bignerdcoding)
- [bqlin](https://github.com/bqlin)
- [Byelaney](https://github.com/Byelaney)
- [CMB](https://github.com/chenmingbiao)
- [DarrenChen123](https://github.com/DarrenChen123)
- [dzyding](https://github.com/dzyding)
- [Hale](https://github.com/wuqiuhao)
- [jojotov](https://github.com/jojotov)
- [Khala-wan](https://github.com/Khala-wan)
- [Nemocdz](https://github.com/Nemocdz)
- [numbbbbb](https://github.com/numbbbbb)
- [WAMaker](https://github.com/WAMaker)
- [Yousanflics](https://github.com/Yousanflics)
## Swift 4.x 主要贡献者
- [Adolf-L](https://github.com/Adolf-L)
- [BigNerdCoding](https://github.com/bignerdcoding)
- [bqlin](https://github.com/bqlin)
- [Cee](https://github.com/Cee)
- [CMB](https://github.com/chenmingbiao)
- [Damonwong](https://github.com/Damonvvong)
- [Desgard](https://github.com/Desgard)
- [dzyding](https://github.com/dzyding)
- [EyreFree](https://www.eyrefree.org/)
- [Forelas](https://github.com/ForelaxX)
- [Hale](https://github.com/wuqiuhao)
- [kemchenj](https://kemchenj.github.io)
- [jojotov](https://github.com/jojotov)
- [Meler](https://github.com/pmtao)
- [mobilefellow](https://github.com/mobilefellow)
- [muhlenXi](https://github.com/muhlenxi)
- [mylittleswift](https://github.com/mylittleswift)
- [Nemocdz](https://github.com/Nemocdz)
- [numbbbbb](https://github.com/numbbbbb)
- [rain2540](https://github.com/rain2540)
- [Rsenjoyer](https://github.com/Rsenjoyer)
- [WAMaker](https://github.com/WAMaker)
- [YiYiZheng](https://github.com/YiYiZheng)
- [ZhangChi](https://github.com/zhangchi25806)
## Swift 3.x 主要贡献者
- [bqlin](https://github.com/bqlin)
- [chenmingjia](https://github.com/chenmingjia)
- [CMB](https://github.com/chenmingbiao)
- [crayygy](https://github.com/crayygy)
- [kemchenj](https://kemchenj.github.io)
- [Lanford](https://github.com/LanfordCai)
- [mmoaay](https://github.com/mmoaay)
- [mylittleswift](https://github.com/mylittleswift)
- [qhd](https://github.com/qhd)
- [shanks](https://github.com/shanksyang)
## Swift 2.x 主要贡献者
- [100mango](https://github.com/100mango)
- [175](https://github.com/Brian175)
- [BridgeQ](https://github.com/WXGBridgeQ)
- [buginux](https://github.com/buginux)
- [Cee](https://github.com/Cee)
- [Channe](https://github.com/Channe)
- [CMB](https://github.com/chenmingbiao)
- [DianQK](https://github.com/DianQK)
- [dreamkidd](https://github.com/dreamkidd)
- [EudeMorgen](https://github.com/EudeMorgen)
- [futantan](https://github.com/futantan)
- [JackAlan](https://github.com/AlanMelody)
- [KYawn](https://github.com/KYawn)
- [Lanford](https://github.com/LanfordCai)
- [Lenhoon](https://github.com/Lenhoon)
- [littledogboy](https://github.com/littledogboy)
- [LinusLing](https://github.com/linusling)
- [lyojo](https://github.com/lyojo)
- [miaosiqi](https://github.com/miaosiqi)
- [mmoaay](https://github.com/mmoaay)
- [overtrue](https://github.com/overtrue)
- [pmst](https://github.com/colourful987)
- [Prayer](https://github.com/futantan)
- [qhd](https://github.com/qhd)
- [ray16897188](https://github.com/ray16897188)
- [Realank](https://github.com/realank)
- [saitjr](https://github.com/saitjr)
- [SergioChan](https://github.com/SergioChan)
- [shanks](https://github.com/shanksyang)
- [SketchK](https://github.com/SketchK)
- [SkyJean](https://github.com/SkyJean)
- [wardenNScaiyi](https:github.com/wardenNScaiyi)
- [xtymichael](https://github.com/xtymichael)
- [yangsiy](https://github.com/yangsiy)
- [星夜暮晨](https://github.com/semperidem)
- [小铁匠 Linus](https://github.com/kevin833752)
## Swift 1.x 主要贡献者
- [bruce0505](https://github.com/bruce0505)
- [changkun](http://changkun.us/about/)
- [ChildhoodAndy](http://childhood.logdown.com)
- [coverxit](https://github.com/coverxit)
- [dabing1022](https://github.com/dabing1022)
- [EvilCome](https://github.com/Evilcome)
- [feiin](https://github.com/feiin)
- [fd5788](https://github.com/fd5788)
- [geek5nan](https://github.com/geek5nan)
- [happyming](https://github.com/happyming)
- [Hawstein](https://github.com/Hawstein)
- [honghaoz](https://github.com/honghaoz)
- [JaceFu](http://www.devtalking.com/)
- [Jasonbroker](https://github.com/Jasonbroker)
- [JaySurplus](https://github.com/JaySurplus)
- [Lenhoon](https://github.com/marsprince)
- [lifedim](https://github.com/lifedim)
- [Lin-H](https://github.com/Lin-H)
- [lslxdx](https://github.com/lslxdx)
- [LunaticM](https://github.com/LunaticM)
- [lyuka](https://github.com/lyuka)
- [marsprince](https://github.com/marsprince)
- [menlongsheng](https://github.com/menlongsheng)
- [NicePiao](https://github.com/NicePiao)
- [numbbbbb](https://github.com/numbbbbb)
- [pp-prog](https://github.com/pp-prog)
- [sg552](https://github.com/sg552)
- [stanzhai](https://github.com/stanzhai)
- [shinyzhu](https://github.com/shinyzhu)
- [superkam](https://github.com/superkam)
- [takalard](https://github.com/takalard)
- [TimothyYe](https://github.com/TimothyYe)
- [vclwei](https://github.com/vclwei)
- [wh1100717](https://github.com/wh1100717)
- [xiehurricane](https://github.com/xiehurricane)
- [XieLingWang](https://github.com/xielingwang)
- [yangsiy](https://github.com/yangsiy)
- [yankuangshi](https://github.com/yankuangshi)
- [yeahdongcn](https://github.com/yeahdongcn)
- [yangsiy](https://github.com/yangsiy)
- [zqp](https://github.com/zqp)
- [成都老码团队翻译组-Arya](http://weibo.com/littlekok/)
- [成都老码团队翻译组-Oberyn](http://weibo.com/u/5241713117)
# 3.0 译者记录
相关[issue](https://github.com/numbbbbb/the-swift-programming-language-in-chinese/issues/628)
- Functions: [crayygy](https://github.com/crayygy)
- Control Flow: [Realank](https://github.com/Realank)
- Closures: [LanfordCai](https://github.com/LanfordCai)
- Protocols: [chenmingbiao](https://github.com/chenmingbiao)
- The Basics:[chenmingbiao](https://github.com/chenmingbiao)
- Advanced Operators: [mmoaay](https://github.com/mmoaay)
Language Reference:
- Attributes: [WhoJave](https://github.com/WhoJave)
- Statements: [chenmingjia](https://github.com/chenmingjia)
- Declarations: [chenmingjia](https://github.com/chenmingjia)
- Expressions: [chenmingjia](https://github.com/chenmingjia)
- Types: [lettleprince](https://github.com/lettleprince)
- Generic Parameters and Arguments: [chenmingjia](https://github.com/chenmingjia)
感谢阅读!

View File

@ -1,47 +1,49 @@
# Summary
* [Introduction](README.md)
* 欢迎使用 Swift
* [关于 Swift](chapter1/01_about_swift.md)
* [版本兼容性](chapter1/02_version_compatibility.md)
* [Swift 初见](chapter1/03_a_swift_tour.md)
* [Swift 版本历史记录](chapter1/04_revision_history.md)
* [关于 Swift](chapter1/01_about_swift.md)
* [版本兼容性](chapter1/02_version_compatibility.md)
* [Swift 初见](chapter1/03_a_swift_tour.md)
* [Swift 版本历史记录](chapter1/04_revision_history.md)
* Swift 教程
* [基础部分](chapter2/01_The_Basics.md)
* [基本运算符](chapter2/02_Basic_Operators.md)
* [字符串和字符](chapter2/03_Strings_and_Characters.md)
* [集合类型](chapter2/04_Collection_Types.md)
* [控制流](chapter2/05_Control_Flow.md)
* [函数](chapter2/06_Functions.md)
* [闭包](chapter2/07_Closures.md)
* [枚举](chapter2/08_Enumerations.md)
* [类和结构体](chapter2/09_Structures_And_Classes.md)
* [属性](chapter2/10_Properties.md)
* [方法](chapter2/11_Methods.md)
* [下标](chapter2/12_Subscripts.md)
* [继承](chapter2/13_Inheritance.md)
* [构造过程](chapter2/14_Initialization.md)
* [析构过程](chapter2/15_Deinitialization.md)
* [可选链](chapter2/16_Optional_Chaining.md)
* [错误处理](chapter2/17_Error_Handling.md)
* [类型转换](chapter2/18_Type_Casting.md)
* [嵌套类型](chapter2/19_Nested_Types.md)
* [扩展](chapter2/20_Extensions.md)
* [协议](chapter2/21_Protocols.md)
* [泛型](chapter2/22_Generics.md)
* [自动引用计数](chapter2/23_Automatic_Reference_Counting.md)
* [内存安全](chapter2/24_Memory_Safety.md)
* [访问控制](chapter2/25_Access_Control.md)
* [高级运算符](chapter2/26_Advanced_Operators.md)
* [基础部分](chapter2/01_The_Basics.md)
* [基本运算符](chapter2/02_Basic_Operators.md)
* [字符串和字符](chapter2/03_Strings_and_Characters.md)
* [集合类型](chapter2/04_Collection_Types.md)
* [控制流](chapter2/05_Control_Flow.md)
* [函数](chapter2/06_Functions.md)
* [闭包](chapter2/07_Closures.md)
* [枚举](chapter2/08_Enumerations.md)
* [类和结构体](chapter2/09_Structures_And_Classes.md)
* [属性](chapter2/10_Properties.md)
* [方法](chapter2/11_Methods.md)
* [下标](chapter2/12_Subscripts.md)
* [继承](chapter2/13_Inheritance.md)
* [构造过程](chapter2/14_Initialization.md)
* [析构过程](chapter2/15_Deinitialization.md)
* [可选链](chapter2/16_Optional_Chaining.md)
* [错误处理](chapter2/17_Error_Handling.md)
* [类型转换](chapter2/18_Type_Casting.md)
* [嵌套类型](chapter2/19_Nested_Types.md)
* [扩展](chapter2/20_Extensions.md)
* [协议](chapter2/21_Protocols.md)
* [泛型](chapter2/22_Generics.md)
* [自动引用计数](chapter2/23_Automatic_Reference_Counting.md)
* [内存安全](chapter2/24_Memory_Safety.md)
* [访问控制](chapter2/25_Access_Control.md)
* [高级运算符](chapter2/26_Advanced_Operators.md)
* 语言参考
* [关于语言参考](chapter3/01_About_the_Language_Reference.md)
* [词法结构](chapter3/02_Lexical_Structure.md)
* [类型](chapter3/03_Types.md)
* [表达式](chapter3/04_Expressions.md)
* [语句](chapter3/05_Statements.md)
* [声明](chapter3/06_Declarations.md)
* [特性](chapter3/07_Attributes.md)
* [模式](chapter3/08_Patterns.md)
* [泛型参数](chapter3/09_Generic_Parameters_and_Arguments.md)
* [语法总结](chapter3/10_Summary_of_the_Grammar.md)
* [关于语言参考](chapter3/01_About_the_Language_Reference.md)
* [词法结构](chapter3/02_Lexical_Structure.md)
* [类型](chapter3/03_Types.md)
* [表达式](chapter3/04_Expressions.md)
* [语句](chapter3/05_Statements.md)
* [声明](chapter3/06_Declarations.md)
* [特性](chapter3/07_Attributes.md)
* [模式](chapter3/08_Patterns.md)
* [泛型参数](chapter3/09_Generic_Parameters_and_Arguments.md)
* [语法总结](chapter3/10_Summary_of_the_Grammar.md)
* 翻译贡献者
* [翻译贡献者](contributors.md)
* [翻译贡献者](contributors.md)

View File

@ -1,6 +1,6 @@
# 版本兼容性
本书描述的是在 Xcode 10.2 中的默认 Swift 版本 Swift 5。你可以使用 Xcode10.2 来构建 Swift 5、Swift 4.2 或 Swift 写的项目
本书描述的是在 Xcode 10.2 中的默认 Swift 版本 Swift 5。你可以使用 Xcode10.2 来构建 Swift 5、Swift 4.2 或 Swift 4 写的项目
当您使用 Xcode 10.2 构建 Swift 4 和 Swift 4.2 代码时,除了下面的功能仅支持 Swift 5其他大多数功能都依然可用。

View File

@ -71,7 +71,7 @@ var red, green, blue: Double
> 注意
>
> 一般来说你很少需要写类型标注。如果你在声明常量或者变量的时候赋了一个初始值Swift 可以推断出这个常量或者变量的类型,请参考[类型安全和类型推断](#type_safety_and_type_inference)。在上面的例子中,没有给 `welcomeMessage` 赋初始值,所以变量 `welcomeMessage` 的类型是通过一个类型标注指定的,而不是通过初始值推断的。
> 一般来说你很少需要写类型标注。如果你在声明常量或者变量的时候赋了一个初始值Swift 可以推断出这个常量或者变量的类型,请参考[类型安全和类型推断](#type-safety-and-type-inference)。在上面的例子中,没有给 `welcomeMessage` 赋初始值,所以变量 `welcomeMessage` 的类型是通过一个类型标注指定的,而不是通过初始值推断的。
### 常量和变量的命名 {#naming}
@ -762,7 +762,7 @@ if age > 10 {
precondition(index > 0, "Index must be greater than zero.")
```
你可以调用 `precondition(_:_:file:line:)` 方法来表明出现了一个错误例如switch 进入了 default 分支,但是所有的有效值应该被任意一个其他分支(非 default 分支)处理。
你可以调用 `preconditionFailure(_:file:line:)` 方法来表明出现了一个错误例如switch 进入了 default 分支,但是所有的有效值应该被任意一个其他分支(非 default 分支)处理。
> 注意
>

View File

@ -434,7 +434,7 @@ welcome.removeSubrange(range)
```swift
let greeting = "Hello, world!"
let index = greeting.index(of: ",") ?? greeting.endIndex
let index = greeting.firstIndex(of: ",") ?? greeting.endIndex
let beginning = greeting[..<index]
// beginning 的值为 "Hello"

View File

@ -95,7 +95,7 @@ var ncc1701 = Starship(name: "Enterprise", prefix: "USS")
// ncc1701.fullName 为 "USS Enterprise"
```
`Starship`只能`fullName` 作为只读的计算属性来实现。每一个 `Starship` 类的实例都有一个名为 `name` 的非可选属性和一个名为 `prefix` 的可选属性。 当 `prefix` 存在时,计算属性 `fullName` 会将 `prefix` 插入到 `name` 之前,从而得到一个带有 `prefix``fullName`
`Starship` 类把 `fullName` 作为只读的计算属性来实现。每一个 `Starship` 类的实例都有一个名为 `name` 的非可选属性和一个名为 `prefix` 的可选属性。 当 `prefix` 存在时,计算属性 `fullName` 会将 `prefix` 插入到 `name` 之前,从而得到一个带有 `prefix``fullName`
## 方法要求 {#method-requirements}

View File

@ -42,7 +42,7 @@ Open 只能作用于类和类的成员,它和 Public 的区别如下:
### 访问级别基本原则 {#guiding-principle-of-access-levels}
Swift 中的访问级别遵循一个基本原则:*不可以在某个实体中定义访问级别更低(更严格)的实体*。
Swift 中的访问级别遵循一个基本原则:*实体不能定义在具有更低访问级别(更严格)的实体*。
例如:
@ -65,7 +65,7 @@ Swift 中的访问级别遵循一个基本原则:*不可以在某个实体中
> 注意
>
> 框架依然会使用默认的 `internal` ,也可以指定为 `fileprivate` 访问或者 `private` 访问级别。当你想把某个实体作为框架的 API 的时候,需显式为其指定开放访问或公开访问级别
> 框架的内部实现仍然可以使用默认的访问级别 `internal`,当你需要对框架内部其它部分隐藏细节时可以使用 `private` 或 `fileprivate`。对于框架的对外 API 部分,你就需要将它们设置为 `open` 或 `public` 了
### 单元测试 target 的访问级别 {#access-levels-for-unit-test-targets}
@ -98,7 +98,7 @@ var someInternalConstant = 0 // 隐式 internal
如果想为一个自定义类型指定访问级别,在定义类型时进行指定即可。新类型只能在它的访问级别限制范围内使用。例如,你定义了一个 `fileprivate` 级别的类,那这个类就只能在定义它的源文件中使用,可以作为属性类型、函数参数类型或者返回类型,等等。
一个类型的访问级别也会影响到类型*成员*(属性、方法、构造器、下标)的默认访问级别。如果你将类型指定为 `private` 或者 `fileprivate` 级别,那么该类型的所有成员的默认访问级别也会变成 `private` 或者 `fileprivate` 级别。如果你将类型指定为公开或者 `internal` (或者不明确指定访问级别,而使用默认的 `internal` ),那么该类型的所有成员的默认访问级别将是内部访问
一个类型的访问级别也会影响到类型*成员*(属性、方法、构造器、下标)的默认访问级别。如果你将类型指定为 `private` 或者 `fileprivate` 级别,那么该类型的所有成员的默认访问级别也会变成 `private` 或者 `fileprivate` 级别。如果你将类型指定为 `internal` `public`(或者不明确指定访问级别,而使用默认的 `internal` ),那么该类型的所有成员的默认访问级别将是 `internal`
> 重点
>

View File

@ -1,6 +1,6 @@
# 文档翻译 & 校对工作记录
Swift 官方文档中文翻译工作由[numbbbbb](https://github.com/numbbbbb)发起并主导,该工作已经得到了苹果官方的认可。下面是各个版本官方文档翻译和校对工作的主要贡献者,排名不分先后。
Swift 官方文档中文翻译由 [numbbbbb](https://github.com/numbbbbb) 发起并主导,本项目已经得到了苹果官方的 [认可](https://swift.org/documentation/)Translations 部分)。下面是各个版本官方文档翻译和校对工作的主要贡献者,排名不分先后。
## Swift 5.x 主要贡献者

Binary file not shown.

Before

Width:  |  Height:  |  Size: 576 KiB

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB