2
我想将我在项目中使用的Pod转换为Swift 3.我没有写它,但原作者并没有更新它,所以我分叉它,我试图自己做。但是......无法将(Timer!) - > Void转换为(((CFRunLoopTimer?) - > Void)! - 将NSTimer扩展转换为Swift 3
我得到这个错误试图扩展转换为NSTimer
斯威夫特3: Cannot convert value of type '(Timer!) -> Void' to expected argument type '((CFRunLoopTimer?) -> Void)!
看来,斯威夫特3处理器类型,(Timer!) -> Void
不与老同学CFRunLoop
风格处理程序兼容,但我不知道如何转换这一点,同时保持与iOS 9的兼容性。
我粘贴下面的代码,由Xcode转换。您可以在https://github.com/entotsu/TKSubmitTransition/blob/master/SubmitTransition/Classes/NSTimerEx.swift
干杯
找到原来的代码import Foundation
extension Timer {
class func schedule(delay delay: TimeInterval, handler: (Timer!) -> Void) -> NSTimer {
let fireDate = delay + CFAbsoluteTimeGetCurrent()
let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, 0, 0, 0, handler) // Error on this line
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes)
return timer
}
class func schedule(repeatInterval interval: TimeInterval, handler: @escaping (Timer!) -> Void) -> Timer {
let fireDate = interval + CFAbsoluteTimeGetCurrent()
let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, interval, 0, 0, handler) // And this line
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes)
return timer
}
}
谢谢!这解决了 –