2016-07-01 46 views
7

我想为Swift 3创建一个CocoaPod。因为CocoaPods使用NimbleQuick,并且这些库还没有更新,我分叉了回购并试图转换它们。SetTimer在Swift 3中被弃用了吗?

在敏捷项目中有一个叫做用的签名功能:

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

编译器说: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) 

自动完成节目的所有SetTimer的方法已被弃用,但我应该不会是found

是否有替代品?

回答

0

在Xcode中8 Beta 1中,该方法的签名是:

public func setTimer(start: DispatchTime, 
        interval: DispatchTimeInterval, 
        leeway: DispatchTimeInterval = default) 

如果你在正确的DispatchTimeDispatchTimeInterval参数插上它会编译,你会看到一个弃用警告:

'setTimer(start:leeway:)' is deprecated: replaced by 
instance method 'DispatchSourceTimer.scheduleOneshot(deadline:leeway:)' 

与往常一样,命令+单击这些Swift类和方法将使您进入声明这些方法的Swift接口源。

7

在雨燕3.0,你应该使用

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)) 

,而不是,这是为我工作

相关问题