Skip to content

Commit

Permalink
Migrate to Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
marrony committed May 2, 2019
1 parent 7cfe6a2 commit eea19da
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 25 deletions.
30 changes: 25 additions & 5 deletions FaunaDB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,15 @@
OBJ_1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1010;
TargetAttributes = {
OBJ_39 = {
LastSwiftMigration = 1010;
};
OBJ_62 = {
LastSwiftMigration = 1010;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "FaunaDB" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -312,11 +320,13 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand Down Expand Up @@ -361,11 +371,13 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand Down Expand Up @@ -404,6 +416,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
HEADER_SEARCH_PATHS = "";
Expand All @@ -414,7 +427,8 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
TARGET_NAME = FaunaDB;
};
name = Debug;
Expand All @@ -423,6 +437,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
HEADER_SEARCH_PATHS = "";
Expand All @@ -433,7 +448,8 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
TARGET_NAME = FaunaDB;
};
name = Release;
Expand All @@ -442,13 +458,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = FaunaDB.xcodeproj/FaunaDBTests_Info.plist;
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
TARGET_NAME = FaunaDBTests;
};
name = Debug;
Expand All @@ -457,13 +475,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = FaunaDB.xcodeproj/FaunaDBTests_Info.plist;
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
TARGET_NAME = FaunaDBTests;
};
name = Release;
Expand Down
4 changes: 1 addition & 3 deletions FaunaDB.xcodeproj/xcshareddata/xcschemes/FaunaDB.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -47,7 +46,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
17 changes: 16 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// swift-tools-version:4.2.0
import PackageDescription

let package = Package(
name: "FaunaDB"
name: "FaunaDB",
products: [
.library(name: "FaunaDB", targets: ["FaunaDB"])
],
targets: [
.target(
name: "FaunaDB",
dependencies: []
),
.testTarget(
name: "FaunaDBTests",
dependencies: ["FaunaDB"]
)
]
)

4 changes: 2 additions & 2 deletions Sources/FaunaDB/AtomicInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ internal final class AtomicInt {

return res
}

func update(maxTo newValue: Int) {
lock.sync {
current = max(newValue, current)
}
}

func get() -> Int {
return current
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/FaunaDB/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import Foundation
*/
public final class Client {

private static let defaultEndpoint: URL! = URL(string: "https://db.fauna.com")
public static let DefaultEndpoint: URL! = URL(string: "https://db.fauna.com")
private static let resourcesField = Field<Value>("resource")

private let session: URLSession
private let endpoint: URL
private let auth: String
private let lastSeenTxn: AtomicInt

/**
- Parameters:
- secret: The key's secret to be used to authenticate requests.
- endpoint: The URL address of your FaunaDB server. Default: https://db.fauna.com.
- session: The `URLSession` object to be used while performing HTTP requests to FaunaDB.
Default: `URLSession(configuration: URLSessionConfiguration.default)`.
*/
public convenience init(secret: String, endpoint: URL = defaultEndpoint, session: URLSession? = nil) {
public convenience init(secret: String, endpoint: URL = DefaultEndpoint, session: URLSession? = nil) {
self.init(secret: secret,
endpoint: endpoint,
session: session,
lastSeenTxn: Client.newLastSeenTxn())
}
private init(secret: String, endpoint: URL = defaultEndpoint, session: URLSession? = nil, lastSeenTxn: AtomicInt) {

private init(secret: String, endpoint: URL = DefaultEndpoint, session: URLSession? = nil, lastSeenTxn: AtomicInt) {
self.auth = "Basic \((secret.data(using: .ascii) ?? Data()).base64EncodedString()):"
self.endpoint = endpoint
self.lastSeenTxn = lastSeenTxn
Expand All @@ -44,7 +44,7 @@ public final class Client {
self.session = URLSession(configuration: URLSessionConfiguration.default)
}
}

private static func newLastSeenTxn() -> AtomicInt {
let name = "FaunaDB.LastSeenTxn-" + UUID().uuidString
return AtomicInt(label: name, initial: 0)
Expand Down Expand Up @@ -100,14 +100,14 @@ public final class Client {
try value.get()
}
}

/**
Get the freshest timestamp reported to this client.
*/
public func getLastTxnTime() -> Int {
return lastSeenTxn.get()
}

/**
Sync the freshest timestamp seen by this client.

Expand All @@ -130,7 +130,7 @@ public final class Client {
request.addValue("application/json;charset=utf-8", forHTTPHeaderField: "Content-Type")
request.addValue(auth, forHTTPHeaderField: "Authorization")
request.addValue("2.1", forHTTPHeaderField: "X-FaunaDB-API-Version")

let txnTime = lastSeenTxn.get()
if txnTime > 0 {
request.addValue("\(txnTime)", forHTTPHeaderField: "X-Last-Txn-Time")
Expand Down Expand Up @@ -182,7 +182,7 @@ public final class Client {
if let txnHeaderValue = response.allHeaderFields["X-Txn-Time"] as? String, let txnTime = Int(txnHeaderValue) {
syncLastTxnTime(txnTime)
}

if let error = Errors.errorFor(response: response, json: data) {
failureCallback(error)
return
Expand Down
2 changes: 1 addition & 1 deletion Sources/FaunaDB/Expr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension Fn {

internal func fn(_ pairs: (String, Expr?)...) -> Fn.Call {
return Dictionary(pairs:
pairs.flatMap { (key, value) in
pairs.compactMap { (key, value) in
guard let value = value else { return nil }
return (key, value)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FaunaDB/Field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ extension Collect {

return try cast(
convert(collected:
try decompose(value: value).flatMap {
try decompose(value: value).compactMap {
try collectField(segment: $0.0, value: $0.1)
}
)
Expand Down
1 change: 1 addition & 0 deletions Sources/FaunaDB/LanguageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal extension Dictionary {

}

@nonobjc
internal extension NSNumber {

func isBoolNumber() -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions Tests/FaunaDBTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ class ClientTests: XCTestCase {
let keyQueried = try! rootClient.query(KeyFromSecret(secret)).await()

XCTAssertEqual(
try keyQueried.get("ref") as RefV!,
try keyCreated.get("ref") as RefV!
try keyQueried.get("ref") as RefV?,
try keyCreated.get("ref") as RefV?
)
}

Expand Down

0 comments on commit eea19da

Please sign in to comment.