A look into Grand Central Dispatch, NSOperationQueues, NSOperations, Barriers, Dispatch Queues, Dispatch Groups, and more with a sample project and code to explore

There are hosts of write-ups online about iOS concurrency. Many of them are good. Some are lacking. But most are pretty targeted in my experience, meaning you have to know what you’re looking for before you can stumble across the guides. There are a few general purpose ones out there still, but I wanted to contribute to the communal knowledge pool and introduce a wide array of concurrency-related topics in one post/series. For the less popular/used portions I’ll include small tidbits with links.

My previous posts have been more deep dive-y (though there is plenty of depth left to explore…


Building the Layout

The Layout

I think a lot of the “skill” in development, the kind we can all cultivate over time, is seeing an issue (or a potential enhancement) and figuring out where we should look, and what the correct fix is. While StackOverflow may have some “clever” tricks that can reside within your cell or your collection view controller, something that is very rarely recommended is building out a layout to… fix your layout. We noted earlier that our cells were the wrong size and they weren’t really laying out how we wanted. These are layout issues.

I feel like that point is…


Setting Up the Views and Controller

Note: I’ll be splitting this post up into multiple pieces so it’s more manageable. Some things are more intuitive and already known by more experienced developers; some parts may not be. This first post in particular doesn’t have much more than my personal preferences on structuring views and serves largely to give a starting point for the complexities of part 2. If you’re super super new to collection view controllers, I won’t go into how to set up delegates/data sources and the like. This is better to read if you’ve used them a few times and know the basics.

Introduction

While…


Introduction

I’m a bit late to the game (safe areas were introduced at WWDC 2017, yet WWDC 2018 is 31 days (!) from today), but I feel that “deeper dives” into frequently used UIKit APIs are timeless pieces, even after they’re deprecated. Developers often have to deal with legacy APIs long after Apple deprecates them, and even if that’s not the case, knowing how things work past the basics helps understand newer APIs and helps clarify how Apple intends for things to work.

Note that I won’t spend too much time talking about the basics, as they’re pretty established. I’d more…


I wrote a few pieces previously on how extended layout worked in iOS 10 and how Apple’s updated the functionality in iOS 11. The gist of it is that Apple wants our scrollable content to go underneath stuff (home indicator, status bars, navigation bars, toolbars) and it accomplishes this by having us constrain our scroll views to go underneath bars, but they’ll set our contentInset so we can still scroll things into view. Simple enough.

Before iOS 11, the method by which Apple did this is through the automaticallyAdjustsScrollViewInsets property on UIViewController, which terrifies me because it:

  • has the terrifying…


Let me start off by saying that this Medium post explains the new APIs better than I could, complete with pretty gifs and lots of screenshots and sample code. What I’m more interested in right now, though, is how we’re expected to go from iOS 10 APIs to iOS 11, not necessarily how to use iOS 11 out-of-the-box.

If we’re supporting an iOS 10 app right now, how do we upgrade it to become an iOS 11 app? What properties have been deprecated and what should I use instead? What’s different about them?

What if we need to support both…


Note: topLayoutGuide and bottomLayoutGuide have been deprecated in iOS 11. It’s worth understanding them for dealing with iOS 10 code and to give yourself a nice starting place for learning about what changed in iOS 11.

In my last post I discussed what extended layout was in iOS and briefly touched on UIViewController’s topLayoutGuide. Because the post wasn’t centered around layout guides I didn’t go too far into it. It’s something worth knowing and a prerequisite (at least in my eyes) to understand the changes Apple made in iOS 11 to accommodate the iPhone X, so we’ll explore that today.


I’ve noticed a lot of people online (i.e. StackOverflow) that jump to a handful of UIViewController properties when their views aren’t laying out properly, then manipulate them almost randomly to get the behavior they want. This invariably leads to the “accepted” answer to layout issue being “set automaticallyAdjutstsScrollViewInsets to [true/false]” or “set edgesForExtendedLayout to UIRectEdgeZero” with one person saying “thanks, that fixed it!” and five others saying “that didn’t fix it pls help”. Even in Apple’s WWDC videos there’s no super clear explanation of how these APIs work and what effects they have on each other, although there are broad…

Ryan Fox

iOS developer @Facebook — the opinions expressed here are mine and do not necessarily represent those of my employer. https://www.linkedin.com/in/wailord

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store