DISPATCH_TIME_NOW in fast version 3 and backward compatibility

In accordance with this brilliant answer to using dispatch_after by @matt, I tried the code on the playground and it works fine (no errors). But when I try to do backward compatibility, since DispatchTime.now() is only available for iOS 10 only like this:

 func delay( _ delay: Double, closure: () -> ()){ guard #available(iOS 10, *) else { dispatch_after( dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)) ), dispatch_get_main_queue(), closure) return } let when = DispatchTime.now() + delay DispatchQueue.main.after(when: when, execute: closure) } 

The compiler offers to fix DISPATCH_TIME_NOW to Replace "DISPATCH_TIME_NOW" with "dispatch_time_t(DISPATCH_TIME_NOW)" and gives an error message

Cannot convert value of type 'Int' to the expected argument type 'dispatch_time_t' (aka 'UInt64')

I tried to fix it as a compiler, but finally ended up with a lot of errors. How do I use backward compatibility here? What bad am I doing? Help, thanks!

+8
ios swift swift3 xcode8
source share
1 answer

DispatchTime.now() , as well as almost any DispatchQueue or DispatchTime method, is available for iOS 7, 8, 9, and 10. The documentation is simply incorrect.

+3
source share

All Articles