From the course: iOS Development: Threading and Grand Central Dispatch
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Dispatching asynchronously
From the course: iOS Development: Threading and Grand Central Dispatch
Dispatching asynchronously
- [Instructor] When you run a task asynchronously, it will start, but will not wait for the task to be completed. Execution is returned to your app immediately, and this frees up your up to do other tasks. It's important to note that cues are based on first in, first out basis, but this doesn't guarantee that the first task submitted will be the first task finished. The FIFA order only applies to when tasks start not when they finish. Here's an example of asynchronous code. Here we have created a queue and we can submit a task to run in the background thread. Once it's done, you can delegate the code back to your main queue by calling DispatchQueue.main.async. We can also execute code asynchronously after a given delay. The task is scheduled for a specific time, and returns immediately. We do this by using the asyncAfter function, which takes a deadline parameter of dispatch time, and an execute parameter of dispatch work…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.