Skip to content

Commit

Permalink
Update for Swift 4
Browse files Browse the repository at this point in the history
Fixes #39.
  • Loading branch information
msanders committed Oct 19, 2017
1 parent 859d451 commit 92241af
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
osx_image: xcode8.3
osx_image: xcode9
language: objective-c
env:
matrix:
Expand Down
9 changes: 5 additions & 4 deletions Cartfile.resolved
@@ -1,4 +1,5 @@
github "Quick/Nimble" "v7.0.1"
github "Quick/Quick" "v1.1.0"
github "antitypical/Result" "3.2.3"
github "typelift/SwiftCheck" "0.8.0"
github "Quick/Nimble" "v7.0.2"
github "Quick/Quick" "v1.2.0"
github "antitypical/Result" "3.2.4"
github "trill-lang/FileCheck" "0.0.3"
github "typelift/SwiftCheck" "0.9.0"
10 changes: 5 additions & 5 deletions Examples/iOS/ViewController.swift
Expand Up @@ -87,11 +87,11 @@ private extension ExampleViewController {
func refresh() {
TrueTimeClient.sharedInstance.fetchIfNeeded { result in
switch result {
case let .success(referenceTime):
self.referenceTime = referenceTime
print("Got network time! \(referenceTime)")
case let .failure(error):
print("Error! \(error)")
case let .success(referenceTime):
self.referenceTime = referenceTime
print("Got network time! \(referenceTime)")
case let .failure(error):
print("Error! \(error)")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NTPClient.swift
Expand Up @@ -116,7 +116,7 @@ private extension NTPClient {
referenceTime.underlyingValue.uptimeInterval)
timer = DispatchSource.makeTimerSource(flags: [], queue: queue)
timer?.setEventHandler(handler: invalidate)
timer?.scheduleOneshot(deadline: .now() + remainingInterval)
timer?.schedule(deadline: .now() + remainingInterval)
timer?.resume()
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NTPExtensions.swift
Expand Up @@ -47,12 +47,12 @@ protocol NTPTimevalConvertible: NTPTimeType {}
extension NTPTimeType {
// Interprets the receiver as an elapsed time in milliseconds.
var durationInMilliseconds: Int64 {
return whole.toIntMax() * Int64(MSEC_PER_SEC) +
return Int64(whole) * Int64(MSEC_PER_SEC) +
fractionInMicroseconds / Int64(USEC_PER_MSEC)
}

var fractionInMicroseconds: Int64 {
return fraction.toIntMax() / Int64(1<<32 / USEC_PER_SEC)
return Int64(fraction) / Int64(1<<32 / USEC_PER_SEC)
}
}

Expand All @@ -64,7 +64,7 @@ extension NTPTimevalConvertible {
}

var milliseconds: Int64 {
return (whole.toIntMax() - secondsFrom1900To1970) * Int64(MSEC_PER_SEC) +
return (Int64(whole) - secondsFrom1900To1970) * Int64(MSEC_PER_SEC) +
fractionInMicroseconds / Int64(USEC_PER_MSEC)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/TimedOperation.swift
Expand Up @@ -22,7 +22,7 @@ extension TimedOperation {
func startTimer() {
cancelTimer()
timer = DispatchSource.makeTimerSource(flags: [], queue: timerQueue)
timer?.scheduleOneshot(deadline: .now() + timeout)
timer?.schedule(deadline: .now() + timeout)
timer?.setEventHandler {
guard self.started else { return }
self.debugLog("Got timeout for \(self)")
Expand Down
38 changes: 16 additions & 22 deletions Sources/TrueTime.swift
Expand Up @@ -50,13 +50,13 @@ public typealias ReferenceTimeCallback = (ReferenceTimeResult) -> Void
public typealias LogCallback = (String) -> Void

@objc public final class TrueTimeClient: NSObject {
public static let sharedInstance = TrueTimeClient()
required public init(timeout: TimeInterval = defaultTimeout,
maxRetries: Int = defaultMaxRetries,
maxConnections: Int = defaultMaxConnections,
maxServers: Int = defaultMaxServers,
numberOfSamples: Int = defaultNumberOfSamples,
pollInterval: TimeInterval = defaultPollInterval) {
@objc public static let sharedInstance = TrueTimeClient()
@objc required public init(timeout: TimeInterval = 8,
maxRetries: Int = 3,
maxConnections: Int = 5,
maxServers: Int = 5,
numberOfSamples: Int = 4,
pollInterval: TimeInterval = 512) {
config = NTPConfig(timeout: timeout,
maxRetries: maxRetries,
maxConnections: maxConnections,
Expand All @@ -66,11 +66,11 @@ public typealias LogCallback = (String) -> Void
ntp = NTPClient(config: config)
}

public func start(hostURLs pools: [URL] = [URL(string: "time.apple.com")!]) {
@objc public func start(hostURLs pools: [URL] = [URL(string: "time.apple.com")!]) {
ntp.start(pools: pools)
}

public func pause() {
@objc public func pause() {
ntp.pause()
}

Expand All @@ -81,19 +81,19 @@ public typealias LogCallback = (String) -> Void
}

#if DEBUG_LOGGING
public var logCallback: LogCallback? = defaultLogger {
@objc public var logCallback: LogCallback? = defaultLogger {
didSet {
ntp.logger = logCallback
}
}
#endif

public var referenceTime: ReferenceTime? { return ntp.referenceTime }
public var timeout: TimeInterval { return config.timeout }
public var maxRetries: Int { return config.maxRetries }
public var maxConnections: Int { return config.maxConnections }
public var maxServers: Int { return config.maxServers}
public var numberOfSamples: Int { return config.numberOfSamples}
@objc public var referenceTime: ReferenceTime? { return ntp.referenceTime }
@objc public var timeout: TimeInterval { return config.timeout }
@objc public var maxRetries: Int { return config.maxRetries }
@objc public var maxConnections: Int { return config.maxConnections }
@objc public var maxServers: Int { return config.maxServers}
@objc public var numberOfSamples: Int { return config.numberOfSamples}

private let config: NTPConfig
private let ntp: NTPClient
Expand Down Expand Up @@ -134,9 +134,3 @@ extension TrueTimeClient {
}

let defaultLogger: LogCallback = { print($0) }
private let defaultMaxConnections: Int = 5
private let defaultMaxRetries: Int = 3
private let defaultMaxServers: Int = 5
private let defaultNumberOfSamples: Int = 4
private let defaultPollInterval: TimeInterval = 512
private let defaultTimeout: TimeInterval = 8
18 changes: 13 additions & 5 deletions TrueTime.xcodeproj/project.pbxproj
Expand Up @@ -650,19 +650,19 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = Instacart;
TargetAttributes = {
280090491D444B64004C788E = {
CreatedOnToolsVersion = 7.3.1;
};
28482DC11D314E7B003491D9 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0810;
LastSwiftMigration = 0900;
};
28482DCB1D314E7B003491D9 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
285047DE1D4D641400DE4CE8 = {
CreatedOnToolsVersion = 7.3.1;
Expand Down Expand Up @@ -1037,8 +1037,12 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -1053,7 +1057,7 @@
SDKROOT = "";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1065,8 +1069,12 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -1079,7 +1087,7 @@
SDKROOT = "";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down

0 comments on commit 92241af

Please sign in to comment.