This is part of the "iOS Data and Networking" learning path. View Path

iOS Concurrency with GCD and Operations

Jun 23 2020 · Video Course (3 hrs, 21 mins) · Beginner

Learn how to add concurrency to your apps! Keep your app’s UI responsive to give your users a great user experience, and learn how to avoid common concurrency problems, like race condition, priority inversion and deadlock.

5/5 7 Ratings

Version

  • Swift 5, iOS 13, Xcode 11

Getting Started

Introduction

8:29 Free

Find out what's in store for you as you work through this course and why it's important.

1

GCD

7:29

Learn about the different Grand Central Dispatch global queues and how they manage threads for you.

2

Develop your understanding of serial vs. concurrent queues and synchronous vs. asynchronous dispatch.

3

Learn how to create and execute a dispatch work item if you want to be notified when the task completes, or if you might need to cancel the task.

4

Practice using dispatch queues to download and display images, through a hands-on challenge.

5

Learn how to use the asynchronous URLSession API to download images in the background, then dispatch back to the main queue to display them.

6

Learn how to create your own asynchronous version of any function, where you can specify the run and completion queues.

7

Practice creating an asynchronous version of a function in a real app, through a hands-on challenge.

8

Learn about two reactive programming frameworks, which unify and coordinate the numerous asynchronous programming tools.

9

Conclusion

2:41

Let's review what you've learned about concurrency and dispatch queues and discuss what's next.

10

Grand Central Dispatch

Find out what you'll learn about concurrency in this part of the course, and why it's important.

11

Learn how to create a group of slow tasks, run them on a dispatch queue and be notified when they all finish.

12

Learn how to wrap an asynchronous function so you can run it in a dispatch group, and it tells the group when it really finishes.

13

In a hands-on challenge, practice wrapping the asynchronous function URLSession dataTask to download a group of images.

14

Learn how to use a dispatch semaphore to control the number of dispatch group tasks that run at the same time.

15

Learn how to prevent the three potential concurrency problems: priority inversion, data races and deadlocks.

16

Explore the priority inversion problem by creating a situation where a high-priority task must wait for lower-priority tasks.

17

Learn how to use Xcode's TSan tool to detect data races, then use a dispatch barrier to make a class threadsafe.

18

Practice using TSan and making a class threadsafe with a dispatch barrier, through a hands-on challenge.

19

Conclusion

2:55

Halfway through this course, let's review what you've learned about concurrency problems and dispatch groups and discuss what's next.

20

Operations I

Let's review what you'll be learning about Operations and OperationQueues in this part of the course, and why it's important.

21

Get started with Operations by learning how to create and use BlockOperations and what they're useful for.

22

Learn how to define a reusable operation, with input and output properties, as a subclass of Operation.

23

Discover the real power of Operations happens when you add them to an OperationQueue and let it handle scheduling and execution.

24

Explore how Operations run on an OperationQueue by executing the same set of tasks you used with BlockOperation.

25

In a hands-on challenge, practice using an OperationQueue to apply a tilt-shift filter to an array of images.

26

Find out what you need to do to run an asynchronous operation in an OperationQueue, so the OperationQueue knows when it really finishes.

27

Create an AsyncOperation subclass of Operation to handle Operation state changes, then subclass AsyncOperation to wrap an asynchronous function.

28

In a hands-on challenge, practice subclassing AsyncOperation to wrap the image download task, then create instances to download an array of images.

29

Conclusion

0:55

Let's review what you've learned in this part about Operations, OperationQueues and AsyncOperations, and discuss what's next.

30

Operations II

Find out what you'll be learning in this part of the course about canceling or defining dependencies on Operations and about Core Data and SwiftUI with Combine.

31

Learn how to set up a dependency between two operations so an OperationQueue can run them in the correct order.

32

In a hands-on challenge, practice defining an Operation dependency to apply the tilt-shift filter after an image finishes downloading.

33

Learn how to cancel download and filter operations in the sample app, if an image's cell scrolls off the screen.

34

Learn the wrong way and the right way to share a Core Data NSManagedObject between threads in an app.

35

Take a walk through a SwiftUI+Combine version of the Concurrency app, using Publishers to download and tilt-shift filter images.

36

Conclusion

1:46

Let's review everything you've learned in this course about Grand Central Dispatch, concurrency problems, Operations and OperationQueues.

37

Who is this for?

Experienced iOS developers, with an intermediate level of knowledge of Swift and iOS development.

Learn how to use dispatch queues and operations in your apps, to keep your app’s UI responsive, and to avoid data races, priority inversion and deadlock. You’ll learn how to manage groups of tasks with dependencies and how to use asynchronous API methods in dispatch groups and operation queues.

Covered concepts

  • Global Dispatch Queues
  • Serial vs. Concurrent Queues
  • Synchronous vs. Asynchronous Dispatch
  • Dispatch Work Item, Dispatch Group, Dispatch Semaphore
  • Data Races, TSan and Threadsafe Classes
  • Quality of Service and Priority Inversion
  • Avoiding Deadlock
  • Operation and OperationQueue
  • Asynchronous Operation
  • Operation Dependencies
  • Canceling Operations
  • Concurrency and Core Data
  • Reactive Frameworks

Contributors

Comments