Skip to content

Commit be653b2

Browse files
committed
Migrate Array2D algorithm to Swift 3
1 parent 025360d commit be653b2

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

Array2D/Array2D.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
public struct Array2D<T> {
77
public let columns: Int
88
public let rows: Int
9-
private var array: [T]
9+
fileprivate var array: [T]
1010

1111
public init(columns: Int, rows: Int, initialValue: T) {
1212
self.columns = columns
1313
self.rows = rows
14-
array = .init(count: rows*columns, repeatedValue: initialValue)
14+
array = .init(repeatElement(initialValue, count: rows*columns))
1515
}
1616

1717
public subscript(column: Int, row: Int) -> T {

Array2D/Array2D.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
public struct Array2D<T> {
77
public let columns: Int
88
public let rows: Int
9-
private var array: [T]
9+
fileprivate var array: [T]
1010

1111
public init(columns: Int, rows: Int, initialValue: T) {
1212
self.columns = columns
1313
self.rows = rows
14-
array = .init(count: rows*columns, repeatedValue: initialValue)
14+
array = .init(repeating: initialValue, count: rows*columns)
1515
}
1616

1717
public subscript(column: Int, row: Int) -> T {

Array2D/Tests/Array2DTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Array2DTest: XCTestCase {
4343
}
4444

4545
func testPerformanceOnSmallArray() {
46-
self.measureBlock {
46+
self.measure {
4747
self.printArrayWith(columns: 2, rows: 2, inititalValue: 1)
4848
}
4949
}
@@ -54,7 +54,7 @@ class Array2DTest: XCTestCase {
5454
// }
5555
// }
5656

57-
private func printArrayWith(columns columns: Int, rows: Int, inititalValue: Int) {
57+
fileprivate func printArrayWith(columns: Int, rows: Int, inititalValue: Int) {
5858
let array = Array2D(columns: columns, rows: rows, initialValue: 4)
5959
for r in 0..<array.rows {
6060
for c in 0..<array.columns {

Array2D/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)