Summary

Writing asynchronous code that is executed across several dispatch queues, threads, or operation queues can be mind-boggling. Instead of executing your code linearly like you might expect, everything is suddenly running simultaneously and out of order. This pattern is really powerful as it ensures that your apps remain responsive, but it can be quite hard to read your own code once you're chaining together several callbacks.

You saw how we used a dispatch queue and a dispatch group earlier when we wrote the FamilyMovies app. At the time it seemed simple enough, but once you realize what's going on and how much we're hopping between threads, it suddenly isn't as simple anymore. This is okay though because asynchronous programming is not an easy task but it truly is essential that you practice and understand this.

After exploring dispatch queues, we took a look at operations. Often, you'll write tasks that depend on each other in some way. We also did this in the FamilyMovies app; we wanted to fetch all updates for movies, before we called the background fetch completion handler. Initially we used a dispatch group for this but in order to improve readability and reusability, we extracted this process into operations.

You saw how you can make use of operations and dependencies to quickly set up a situation where you perform a task, in this case calling the completion handler, after a certain set of other tasks complete first. This makes operations really powerful and fun to work with because they isolate small chunks of work into reusable, chainable components.

It's been mentioned before but if you intend to make use of operations in your app, do make sure to check out Apple's demonstration of Advanced NSOperations from WWDC 2015. Operations are capable of far more than we've just seen and it's strongly recommended to see how Apple uses operations themselves in order to create solid apps.

Once your app is covered by tests, measured with instruments, and improved with asynchronous code and operations, it's probably time that you go and share your app with others. The next and final chapter of this book will show you how to set yourself up for deploying your app through TestFlight and the App Store.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.240