Dispatch source timer not compiling from cli

I've implemented a dispatch source timer that compiles and works on my Mac - but when I compile using the open source toolchain, I get the following error:

Compiler errors:
…/Sources/supervisor.swift:205:20: error: 'schedule(deadline:repeating:leeway:)' is unavailable
supervisorTimer?.schedule(deadline: dTimeTillStart, repeating: DispatchTimeInterval.seconds(interval))
Dispatch.DispatchSourceTimer:15:17: note: 'schedule(deadline:repeating:leeway:)' was introduced in Swift 4
public func schedule(deadline: DispatchTime, repeating interval: DispatchTimeInterval = default, leeway: DispatchTimeInterval = default)

The compiler note seems to suggest the same function signature as I've used in the code. I'm getting the same failure when I add the third parameter (leeway:). And I've done what I can to verify I'm using the latest toolchain:

Compiler termination message:
error: terminated(1): /Library/Developer/Toolchains/swift-4.2-RELEASE.xctoolchain/usr/bin/swift-build-tool -f '/Users/scottlucas/Dropbox/personal/Mad Scientist/Swift Development/Fan/Backend/.build/release.yaml' main output:

Output from ‘swift -version’ command:
Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0

Here's the relevant code from my project:

Actual code:

	supervisorTimer = DispatchSource.makeTimerSource(flags: [], queue: supervisorLoop)
	supervisorTimer?.setEventHandler(handler: self.handler)
	let topOfTheHour = DateComponents(minute: start)
	let startTime = Calendar.current.nextDate(after: Date(), matching: topOfTheHour, matchingPolicy: .nextTime)
		let timeTillStart = startTime?.timeIntervalSinceNow,
		timeTillStart > 0
		else {fatalError("Failed to start weather check loop. File: \(#file), function: \(#function), line: \(#line)")}
	let dTimeTillStart = DispatchTime.now() + DispatchTimeInterval.seconds(Int(timeTillStart))
	supervisorTimer?.schedule(deadline: dTimeTillStart, repeating: DispatchTimeInterval.seconds(interval))

Any ideas why the complier's mad about this? I can replace these functions with the older versions (scheduleRepeating and scheduleOneShot) and it'll compile - although Xcode warns the function's deprecated.


Terms of Service

Privacy Policy

Cookie Policy