1 Commits

Author SHA1 Message Date
373c42e456 fix:示例代码更新 2021-06-23 00:13:20 +08:00
2 changed files with 6 additions and 6 deletions

View File

@ -141,7 +141,7 @@ Swift 为不确定类型提供了两种特殊的类型别名:
这里有个示例,使用 `Any` 类型来和混合的不同类型一起工作,包括函数类型和非类类型。它创建了一个可以存储 `Any` 类型的数组 `things` 这里有个示例,使用 `Any` 类型来和混合的不同类型一起工作,包括函数类型和非类类型。它创建了一个可以存储 `Any` 类型的数组 `things`
```swift ```swift
var things: [Any] = [] var things = [Any]()
things.append(0) things.append(0)
things.append(0.0) things.append(0.0)

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])
} }