Skip to content

Commit 7c6fe7e

Browse files
committed
Merge pull request stephencelis#375 from SebastianOsinski/swift22_fixes
Swift22 fixes
2 parents fd946ac + ddf653b commit 7c6fe7e

File tree

8 files changed

+35
-19
lines changed

8 files changed

+35
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ before_install:
66
- gem install xcpretty --no-document
77
script:
88
- make test
9-
osx_image: xcode7
9+
osx_image: xcode7.3

SQLite/Core/Statement.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,13 @@ extension Cursor : SequenceType {
271271

272272
public func generate() -> AnyGenerator<Binding?> {
273273
var idx = 0
274-
return anyGenerator {
275-
idx >= self.columnCount ? Optional<Binding?>.None : self[idx++]
274+
return AnyGenerator {
275+
if idx >= self.columnCount {
276+
return Optional<Binding?>.None
277+
} else {
278+
idx += 1
279+
return self[idx - 1]
280+
}
276281
}
277282
}
278283

SQLite/Core/Value.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public protocol Number : Binding {}
3333

3434
public protocol Value : Expressible { // extensions cannot have inheritance clauses
3535

36-
typealias ValueType = Self
36+
associatedtype ValueType = Self
3737

38-
typealias Datatype : Binding
38+
associatedtype Datatype : Binding
3939

4040
static var declaredDatatype: String { get }
4141

SQLite/Extensions/FTS4.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ extension Module {
2828
return FTS4([column] + more)
2929
}
3030

31-
@warn_unused_result public static func FTS4(var columns: [Expressible] = [], tokenize tokenizer: Tokenizer? = nil) -> Module {
31+
@warn_unused_result public static func FTS4(columns: [Expressible] = [], tokenize tokenizer: Tokenizer? = nil) -> Module {
32+
var columns = columns
33+
3234
if let tokenizer = tokenizer {
3335
columns.append("=".join([Expression<Void>(literal: "tokenize"), Expression<Void>(literal: tokenizer.description)]))
3436
}

SQLite/Helpers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public func *(_: Expression<Binding>?, _: Expression<Binding>?) -> Expression<Vo
3030

3131
public protocol _OptionalType {
3232

33-
typealias WrappedType
33+
associatedtype WrappedType
3434

3535
}
3636

@@ -88,15 +88,15 @@ extension String {
8888

8989
}
9090

91-
@warn_unused_result func infix<T>(lhs: Expressible, _ rhs: Expressible, wrap: Bool = true, function: String = __FUNCTION__) -> Expression<T> {
91+
@warn_unused_result func infix<T>(lhs: Expressible, _ rhs: Expressible, wrap: Bool = true, function: String = #function) -> Expression<T> {
9292
return function.infix(lhs, rhs, wrap: wrap)
9393
}
9494

95-
@warn_unused_result func wrap<T>(expression: Expressible, function: String = __FUNCTION__) -> Expression<T> {
95+
@warn_unused_result func wrap<T>(expression: Expressible, function: String = #function) -> Expression<T> {
9696
return function.wrap(expression)
9797
}
9898

99-
@warn_unused_result func wrap<T>(expressions: [Expressible], function: String = __FUNCTION__) -> Expression<T> {
99+
@warn_unused_result func wrap<T>(expressions: [Expressible], function: String = #function) -> Expression<T> {
100100
return function.wrap(", ".join(expressions))
101101
}
102102

SQLite/Typed/Expression.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public protocol ExpressionType : Expressible { // extensions cannot have inheritance clauses
2626

27-
typealias UnderlyingType = Void
27+
associatedtype UnderlyingType = Void
2828

2929
var template: String { get }
3030
var bindings: [Binding?] { get }
@@ -78,7 +78,15 @@ extension Expressible {
7878
let expressed = expression
7979
var idx = 0
8080
return expressed.template.characters.reduce("") { template, character in
81-
return template + (character == "?" ? transcode(expressed.bindings[idx++]) : String(character))
81+
let transcoded: String
82+
83+
if character == "?" {
84+
transcoded = transcode(expressed.bindings[idx])
85+
idx += 1
86+
} else {
87+
transcoded = String(character)
88+
}
89+
return template + transcoded
8290
}
8391
}
8492

SQLite/Typed/Query.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ extension Connection {
891891
let e = q.expression
892892
var names = try self.prepare(e.template, e.bindings).columnNames.map { $0.quote() }
893893
if namespace { names = names.map { "\(query.tableName().expression.template).\($0)" } }
894-
for name in names { columnNames[name] = idx++ }
894+
for name in names { columnNames[name] = idx; idx += 1 }
895895
}
896896
}
897897

@@ -914,13 +914,14 @@ extension Connection {
914914
continue
915915
}
916916

917-
columnNames[each.expression.template] = idx++
917+
columnNames[each.expression.template] = idx
918+
idx += 1
918919
}
919920
return columnNames
920921
}()
921922

922923
return AnySequence {
923-
anyGenerator { statement.next().map { Row(columnNames, $0) } }
924+
AnyGenerator { statement.next().map { Row(columnNames, $0) } }
924925
}
925926
}
926927

SQLiteTests/TestHelpers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ class SQLiteTestCase : XCTestCase {
4747
)
4848
}
4949

50-
func AssertSQL(SQL: String, _ executions: Int = 1, _ message: String? = nil, file: String = __FILE__, line: UInt = __LINE__) {
50+
func AssertSQL(SQL: String, _ executions: Int = 1, _ message: String? = nil, file: StaticString = #file, line: UInt = #line) {
5151
XCTAssertEqual(
5252
executions, trace[SQL] ?? 0,
5353
message ?? SQL,
5454
file: file, line: line
5555
)
5656
}
5757

58-
func AssertSQL(SQL: String, _ statement: Statement, _ message: String? = nil, file: String = __FILE__, line: UInt = __LINE__) {
58+
func AssertSQL(SQL: String, _ statement: Statement, _ message: String? = nil, file: StaticString = #file, line: UInt = #line) {
5959
try! statement.run()
6060
AssertSQL(SQL, 1, message, file: file, line: line)
6161
if let count = trace[SQL] { trace[SQL] = count - 1 }
@@ -96,11 +96,11 @@ let int64Optional = Expression<Int64?>("int64Optional")
9696
let string = Expression<String>("string")
9797
let stringOptional = Expression<String?>("stringOptional")
9898

99-
func AssertSQL(@autoclosure expression1: () -> String, @autoclosure _ expression2: () -> Expressible, file: String = __FILE__, line: UInt = __LINE__) {
99+
func AssertSQL(@autoclosure expression1: () -> String, @autoclosure _ expression2: () -> Expressible, file: StaticString = #file, line: UInt = #line) {
100100
XCTAssertEqual(expression1(), expression2().asSQL(), file: file, line: line)
101101
}
102102

103-
func AssertThrows<T>(@autoclosure expression: () throws -> T, file: String = __FILE__, line: UInt = __LINE__) {
103+
func AssertThrows<T>(@autoclosure expression: () throws -> T, file: StaticString = #file, line: UInt = #line) {
104104
do {
105105
try expression()
106106
XCTFail("expression expected to throw", file: file, line: line)

0 commit comments

Comments
 (0)