This course demonstrates practical techniques for adding concurrency to your iOS apps in order to increase responsiveness and more fully utilize the iPhone and iPad hardware. You'll build a solid foundation for using the concurrency APIs by learning how to create and use blocks in Objective-C. You'll learn to use a number of the functions in Apple's Grand Central Dispatch API and how to send code blocks to dispatch queues for both synchronous and concurrent execution. You'll also learn how to use operation queues and how they differ from dispatch queues and when you might choose one over the other. The last module will focus on how to create your own NSOperation subclasses to encapsulate tasks to be executed on operation queues. Performing work concurrently doesn't have to be hard and the APIs provided by Apple have made it easier than ever to take advantage of modern multi-core processors. This course will show you how.
Introduction and Overview Hi, this is Brice Wilson with Pluralsight. Welcome to this course titled Practical iOS Concurrency. You may have heard that writing multithreaded code is hard, error prone, and to be avoided at all costs. That may have been the case at one time, but in recent years Apple has introduced new APIs that make concurrency a feature all developers can implement with confidence. They've not abstracted away all of the pain points that gave multithreaded development a bad reputation, but with an understanding of the new APIs and a practical approach to using them to make your apps incrementally better, concurrent code can be a secret weapon that helps your apps execute faster, feel more responsive, and fully utilize the power available in modern multi-core processors.
Creating and Using Blocks Hi this is Brice Wilson with Pluralsight. In this module we'll see how to create and use block in Objective-C. Technically blocks are an extension to C created by Apple, but since Objective-C is a superset of C, we can use them in our iOS apps. They're an important building block for working with the concurrency APIs, so it's important to fully understand how they work. We'll start with the basics. What are blocks? Once the definitions are in place we'll move on to syntax. Some people find block syntax a bit hard to untangle, I'll try to explain all of the various ways you're likely to encounter blocks in code, and break the syntax down into manageable pieces so it doesn't look quite so messy. Next, we'll talk about variable scope. Blocks can declare their own local variables, but can also use variables declared in the same method as the block itself. We'll see how to do that and examine the rules for when you can and cannot modify those variables. Probably the most common way to use blocks is to declare them inline as parameter to methods. This is primarily how we'll use them in this course, and each new release of the iOS SDK seems to include new methods that accept blocks as parameter, so it's an important technique to begin using and getting comfortable with.
Dispatch Queues Hi, this is Brice Wilson with Pluralsight. In this module we're going to cover Dispatch Queues. As we'll see, they allow you to easily send executable blocks of code to a background thread without the overhead associated with creating and managing those threads yourself. I'll start out with a brief discussion of queues in general, and dispatch queues in particular, and the role they play in iOS concurrency. We'll then look at the two types of dispatch queues that are available, serial queues and concurrent queues. They're both very important and play unique roles in the development of fast and responsive apps.
Operation Queues Hi, this is Brice Wilson with Pluralsight. In this module, we're going to see how to execute code concurrently using Operation Queues. Along with NSOperation objects, they give us a more object-oriented approach to concurrent execution. They can do almost everything a dispatch queue can do, simple serial execution being the primary exception, but they also bring a few new tricks to the party that you can't do with dispatch queues. We'll start by talking about operation queues in general, what they are, and why you might use them. Next, we'll talk about NSOperations, which basically serve as an object wrapper for the blocks of code you want to add to the queue. It's the NSOperation objects that provide much of the additional functionality, beyond what we saw with dispatch queues. Those include the ability to configure interoperation dependencies between operations, so that the tasks in the queue don't just automatically execute in the order they were added to the queue. We'll see how to configure those dependencies, and also examine several other ways you can control operation execution. These include specifying an execution priority for operations, supplying blocks of code to execute when an operation completes, and cancelling operations even after they've been added to the queue. We'll see how to do each of those things.
Creating NSOperation Subclasses Hi, this is Brice Wilson with Pluralsight. In this module we're going to expand on the previous module that covered NSOperation queues and NSOperation objects, and see how we can create our own NSOperation subclasses designed to perform very specific tasks on background threads. Using NSBlockOperation is great, and may meet most of your needs, but creating your own NSOperation subclasses gives you some extra control over precisely how your background tasks execute. In this short module we'll discuss concurrent and non-concurrent operations. Non-concurrent operations are much simpler and are the far more practical solution, so that's where we'll focus our attention when discussing how to define our own NSOperation objects. You'll see that defining your own non-concurrent operation objects is actually quite simple, and by adding cancellation support to your operations, you give the users of your custom operations much more control over how those operations execute.