I’m in the process of migrating older code to Swift 3 and I’m stuck on this one.
How do you create a timer dispatch source?

Old code:

let source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue)

dispatch_source_set_timer(source, dispatch_time(DISPATCH_TIME_NOW, 0), 
UInt64(interval * 1000_000_000), 0)
dispatch_source_set_event_handler(source) {
   // Do something useful
 }

 dispatch_resume(source)

New code:

It should be something like this (untested):

    let timer = DispatchSource.makeTimerSource(flags: ..., queue: queue)
    timer.scheduleRepeating(deadline: ..., interval: ..., leeway: ...)
    timer.setEventHandler {
        ...
    }
    timer.resume()

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to