Concurrency in iOS – Grand Central Dispatch (GCD) with Swift 3

[Download the full Swift Xcode project from GitHub.]
[Download the full Objective-C Xcode project from GitHub.]

I use concurrency in most of my iOS apps, generally to keep the user interface responsive. For those of you new to iOS and/or new to computer science, “Concurrency is the notion of multiple things happening at the same time.” (We can discuss the old “What’s the difference between concurrency and parallelism?” question later.) I’m constantly being asked questions about how to implement concurrency in iOS and, most recently, I’ve received many questions about how to implement it in Swift 3. Here’s a video showing this post’s concurrent Swift code running — and notice that a UIProgressView is updating while images are downloading in the background; notice also that I’m continually pressing a button that increments an instance variable during background processing:

(Make sure you stay with me to complete this discussion of iOS concurrency in the next post. I’ll write some code in Swift 3 and Objective-C showing you the difference between serial and concurrent queues. Before coding we’ll talk about concurrency in general, the terminology used in discussing concurrency (threads, process, and tasks), the differences between the terms “concurrent” and “parallel,” the differences between serial and concurrent queues, the differences between synchronous and asynchronous methods/functions, and finally we’ll wrap up with some more definitions you need to know about.)

The questions about implementing GCD in Swift 3 have come from beginners to intermediate- to even advanced-level developers. For years, the most widely used iOS construct for concurrency — “starting tasks asynchronously” — has been Grand Central Dispatch (GCD). Most iOS old-timers like me have gotten used to GCD’s Objective-C language version of the “dispatch_async” function:

Continue reading “Concurrency in iOS – Grand Central Dispatch (GCD) with Swift 3”

iOS 101 or … Basic animation, Auto Layout, and view geometry – Part 5

[Download the full Xcode project from GitHub.]

Today, I’m going answer all the questions I posed in this series of posts entitled “Basic animation, Auto Layout, and view geometry – Part X” (see parts 1, 2, 3, and 4). I’ll help you understand how how I created the following iPhone animation using Swift 3.0 — and/or how to get started with your first iOS app:

Continue reading “iOS 101 or … Basic animation, Auto Layout, and view geometry – Part 5”