Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Was setTimer deprecated in Swift 3?

I am trying to create a CocoaPod for Swift 3. Because CocoaPods uses Nimble and Quick, and those libraries haven't been updated yet, I forked the repos and am trying to convert them.

In the Nimble project there is a function called with the signature of:

setTimer(start: DispatchTime, interval: UInt64, leeway: UInt64)

The compiler says Cannot invoke 'setTimer' with an argument list of type '(start: DispatchTime, interval: UInt64, leeway: UInt64)'

private let pollLeeway: UInt64 = NSEC_PER_MSEC
let interval = UInt64(pollInterval * Double(NSEC_PER_SEC))
asyncSource.setTimer(start: DispatchTime.now(), interval: interval, leeway: pollLeeway)

The auto-complete shows all the setTimer methods are deprecated, but from what I found they shouldn't be.

Is there a replacement?

like image 678
Caleb Kleveter Avatar asked Jul 01 '16 14:07

Caleb Kleveter


1 Answers

In Swift 3.0 you should use

let timer = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)), queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.default))
    timer.scheduleRepeating(deadline: DispatchTime.init(uptimeNanoseconds: UInt64(100000)), interval: DispatchTimeInterval.seconds(1), leeway: DispatchTimeInterval.seconds(0))

to instead, and it's work for me

like image 158
KingCQ Avatar answered Oct 21 '22 23:10

KingCQ