0

Thanks for the help!

Whenever I enter any code after viewDidLoad or applicationDidFinishLaunching, my view is delayed until after that code has finished. Also tried viewDidAppear.

*Not Using SwiftUI *Running Big Sur Xcode 13.2.1

Let's say I've entered

override func viewDidLoad() {
    super.viewDidLoad()
    
sleep(5) }

The view will load after the sleep... I know sleep isn't a great example, but I've tried it with many functions.

Also if I run any code in AppDelegate - in applicationDidFinishLaunching Same Result.

Any Tips/ Help/ Updates are greatly appreciated!

  • These callbacks are all synchronous and on the main thread. You should only do essential, view-related work on them. Everything else you should push off onto a background queue. – Alexander Feb 10 '22 at 15:20
  • Ahh.. Thanks! Learning more everyday.... Thank you!! – Nick Swoboda Feb 10 '22 at 21:25

1 Answers1

0

You can use DispatchQueue to resolve that issue.

Run your code in another thread using your own queue or predetermined:

override func viewDidLoad() {
    super.viewDidLoad()
    
    DispatchQueue.global(qos: .utility).async {
        //your code here
        sleep(5)
    }
}