Avatar ·

How to create a delay in Swift? Need a simple and reliable way

Hello everyone! I just started learning Swift and Xcode, and I have a problem. I need to pause code execution, for example, to show a loading animation for 2 seconds and then navigate to another screen. In other languages like JavaScript, I just used setTimeout. But in Swift, I haven't found a simple and clear way yet. I tried using Thread.sleep(forTimeInterval: 2), but it seems to completely block the interface — the app freezes for 2 seconds and nothing works. That's definitely not what I need. I've heard about GCD (Grand Central Dispatch) and asyncAfter, but the syntax looks complicated. There's also some Timer, but I'm not sure how to use it correctly for a simple delay. Please tell me the simplest and most correct way to create a delay in Swift, so