1 Commits

Author SHA1 Message Date
1adc64e619 feat:示例代码更新 2021-06-26 11:03:07 +08:00
2 changed files with 6 additions and 6 deletions

View File

@ -135,7 +135,7 @@ swapTwoValues(&someString, &anotherString)
```swift ```swift
struct IntStack { struct IntStack {
var items = [Int]() var items: [Int] = []
mutating func push(_ item: Int) { mutating func push(_ item: Int) {
items.append(item) items.append(item)
} }
@ -153,7 +153,7 @@ struct IntStack {
```swift ```swift
struct Stack<Element> { struct Stack<Element> {
var items = [Element]() var items: [Element] = []
mutating func push(_ item: Element) { mutating func push(_ item: Element) {
items.append(item) items.append(item)
} }
@ -354,7 +354,7 @@ protocol Container {
```swift ```swift
struct IntStack: Container { struct IntStack: Container {
// IntStack 的原始实现部分 // IntStack 的原始实现部分
var items = [Int]() var items: [Int] = []
mutating func push(_ item: Int) { mutating func push(_ item: Int) {
items.append(item) items.append(item)
} }
@ -386,7 +386,7 @@ struct IntStack: Container {
```swift ```swift
struct Stack<Element>: Container { struct Stack<Element>: Container {
// Stack<Element> 的原始实现部分 // Stack<Element> 的原始实现部分
var items = [Element]() var items: [Element] = []
mutating func push(_ item: Element) { mutating func push(_ item: Element) {
items.append(item) items.append(item)
} }
@ -721,7 +721,7 @@ protocol ComparableContainer: Container where Item: Comparable { }
extension Container { extension Container {
subscript<Indices: Sequence>(indices: Indices) -> [Item] subscript<Indices: Sequence>(indices: Indices) -> [Item]
where Indices.Iterator.Element == Int { where Indices.Iterator.Element == Int {
var result = [Item]() var result: [Item] = []
for index in indices { for index in indices {
result.append(self[index]) result.append(self[index])
} }

View File

@ -6,7 +6,7 @@ Swift 的*“词法结构lexical structure”* 描述了能构成该语言
## 空白与注释 {#whitespace} ## 空白与注释 {#whitespace}
空白whitespace有两个用途分隔源文件中的符号和区分前缀、后缀和二元运算符(参见 [运算符](#operators)在其他情况下空白则会被忽略。以下的字符会被当作空白空格U+0020、换行符U+000A、回车符U+000D、水平制表符U+0009、垂直制表符U+000B、换页符U+000C以及空字符U+0000 空白whitespace有两个用途分隔源文件中的符号以及帮助区分运算符属于前缀还是后缀(参见 [运算符](#operators)在其他情况下空白则会被忽略。以下的字符会被当作空白空格U+0020、换行符U+000A、回车符U+000D、水平制表符U+0009、垂直制表符U+000B、换页符U+000C以及空字符U+0000
注释被编译器当作空白处理。单行注释由 `//` 开始直至遇到换行符U+000A或者回车符U+000D。多行注释由 `/*` 开始,以 `*/` 结束。多行注释允许嵌套,但注释标记必须成对出现。 注释被编译器当作空白处理。单行注释由 `//` 开始直至遇到换行符U+000A或者回车符U+000D。多行注释由 `/*` 开始,以 `*/` 结束。多行注释允许嵌套,但注释标记必须成对出现。