Analog of dispatch_after in Swift: how to execute code with a delay via GCD?
Hello everyone! I'm a beginner in Swift and used to write in Objective-C. There, to delay code execution, I used dispatch_after, and everything was simple:
```objc
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"2 seconds passed");
});
```
Now I'm switching to Swift, but I can't find a direct analog. I googled that dispatch_after no longer exists in Swift, and I need to use something else. I tried writing this:
```swift
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
print("2 seconds passed")
}
```
It seems to work, but I'm not sure if it's correct. I'm especially confused by the syntax with `deadline: .now() + 2.0` — I don't understand how it works. For example, if I need to execute code after 0.5 seconds, do I just write