8000 Migrate Stack to Swift 3 · codee/swift-algorithm-club@99c0072 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 99c0072

Browse files
Migrate Stack to Swift 3
1 parent 677f2c2 commit 99c0072

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Stack/Stack.playground/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
public struct Stack<T> {
15-
private var array = [T]()
15+
fileprivate var array = [T]()
1616

1717
public var count: Int {
1818
return array.count
@@ -36,10 +36,10 @@ public struct Stack<T> {
3636
}
3737

3838
// Create a stack and put some elements on it already.
39-
var stackOfNames = Stack(array: ["Carl", "Lisa", "Stephanie", "Jeff", "Wade"])
39+
var stackOfNames = Stack(array:["Carl", "Lisa", "Stephanie", "Jeff", "Wade"])
4040

4141
// Add an element to the top of the stack.
42-
stackOfNames.push("Mike")
42+
stackOfNames.push(element: "Mike")
4343

4444
// The stack is now ["Carl", "Lisa", "Stephanie", "Jeff", "Wade", "Mike"]
4545
print(stackOfNames.array)

Stack/Stack.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Push and pop are O(1) operations.
55
*/
66
public struct Stack<T> {
7-
private var array = [T]()
7+
fileprivate var array = [T]()
88

99
public var isEmpty: Bool {
1010
return array.isEmpty
@@ -14,7 +14,7 @@ public struct Stack<T> {
1414
return array.count
1515
}
1616

17-
public mutating func push(element: T) {
17+
public mutating func push(_ element: T) {
1818
array.append(element)
1919
}
2020

@@ -27,10 +27,10 @@ public struct Stack<T> {
2727
}
2828
}
2929

30-
extension Stack: SequenceType {
31-
public func generate() -> AnyGenerator<T> {
30+
extension Stack: Sequence {
31+
public func makeIterator() -> AnyIterator<T> {
3232
var curr = self
33-
return AnyGenerator {
33+
return AnyIterator {
3434
_ -> T? in
3535
return curr.pop()
3636
}

Stack/Tests/Tests.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
TargetAttributes = {
8989
7B2BBC7F1C779D720067B71D = {
9090
CreatedOnToolsVersion = 7.2;
91+
LastSwiftMigration = 0800;
9192
};
9293
};
9394
};
@@ -220,6 +221,7 @@
220221
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
221222
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
222223
PRODUCT_NAME = "$(TARGET_NAME)";
224+
SWIFT_VERSION = 3.0;
223225
};
224226
name = Debug;
225227
};
@@ -231,6 +233,7 @@
231233
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
232234
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
233235
PRODUCT_NAME = "$(TARGET_NAME)";
236+
SWIFT_VERSION = 3.0;
234237
};
235238
name = Release;
236239
};

0 commit comments

Comments
 (0)
0