Avatar ·

How to properly use dispatch_after in Swift to delay code execution?

Hello! I've just started learning Swift and am trying to understand Grand Central Dispatch. Previously in Objective-C, I often used dispatch_after to execute code with a delay, for example: ```objc dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSLog(@"2 seconds have passed"); }); ``` But now that I'm writing in Swift, I'm not sure how to properly rewrite this code. I tried something like: ```swift dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue()) { print("2 seconds have passed") } ``` But the compiler complains about the syntax. I've seen that in Swift 3 and above, many things have changed in the GCD API, and the old way no longer works. I need to perform a delay before updating U