Is async/await ready for production?

Introduced at WWDC 2021, it will clean up your existing async code… with a little help

A person sitting on the couch, waiting for a text
A person sitting on the couch, waiting for a text

A lot of us have been waiting a long time for async/await syntax in Swift. First proposed in 2017, this API sets out to clean up the pyramid of doom that happens so often with async code. In the WWDC State of the Union, we were introduced to some amazing-looking async code using this syntax. If you’re a professional iOS Developer or learning to become one, you may be wondering if it’s ready for production.

̶I̶M̶H̶O̶ ̶t̶h̶e̶r̶e̶ ̶a̶r̶e̶ ̶s̶o̶m̶e̶ ̶t̶h̶i̶n̶g̶s̶ ̶t̶h̶a̶t̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶c̶h̶a̶n̶g̶e̶ ̶b̶e̶f̶o̶r̶e̶ ̶a̶d̶o̶p̶t̶i̶n̶g̶ ̶t̶h̶e̶ ̶f̶r̶a̶m̶e̶w̶o̶r̶k̶,̶ ̶b̶u̶t̶ ̶u̶l̶t̶i̶m̶a̶t̶e̶l̶y̶,̶ ̶t̶h̶a̶t̶’̶s̶ ̶a̶ ̶d̶e̶c̶i̶s̶i̶o̶n̶ ̶y̶o̶u̶ ̶a̶n̶d̶ ̶y̶o̶u̶r̶ ̶t̶e̶a̶m̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶m̶a̶k̶e̶…

Take your development to the next level, eliminate your assumptions with Unit Tests

Stub -> Fail -> Implement -> Test/Implement/Test Until Pass -> Refactor -> Test/Refactor/Test Until Pass -> Repeat

Don’t you wish you had an automated way to test your code every time you make a change? Good news! You do!

If you’re anything like me, you make a lot of assumptions when you develop software. Also, if you’re anything like me, you probably didn’t realize it until recently, or maybe you still don’t realize it. Trust me when I say, “assuming you aren’t making assumptions is the worst assumption you can make.”

In this article, I’ll introduce you to Test Driven Development by implementing a very simple method and test case. Let’s say we’re developing an e-commerce app and we need to devise a way to add money to the cart. Following the single responsibility principle, this method will only

Increase performance by avoiding retain-cycles

Track down this elusive time-waster in a flash

vertically scrolling numbers, dripping/leaking down the page
vertically scrolling numbers, dripping/leaking down the page
Ew, leaky code

In Swift, memory is handled for us pretty efficiently via ARC. Basically, reference objects (such as classes) hold a count for how many times they’re being referenced. When the count reaches 0, the item is marked for deallocation and removed from memory when the system needs the space.

If we aren’t careful though, we can encounter situations where the memory space never gets marked for deallocation because we’ve created a retain cycle. Unfortunately for us, these can be pretty tricky to track down.

In this tutorial, you’ll implement a unit test that can test any object to see if it’s…

A good API doesn’t break easily

Designing Swift Code with Enums

A little blue character with a repair kit looking at a hole in a website or app
A little blue character with a repair kit looking at a hole in a website or app
Keep those holes closed, so your users don’t experience interruptions!

Often when developing codebases, you probably want to model a situation with one of 2 possible outcomes. In Swift, this often means using optionals as the return type for a method. The idea is one of them will be nil, and the other will be non-nil.

What you may have done in this situation is create a method that returns a tuple with 2 optional parameters. The one that isn’t nil is the one that passed the test. This solves the problem of wanting to know which contains a value. Unfortunately for you, this creates a new problem.

The factory pattern keeps your code clean. Enums keep data flexible

Encapsulate your static initialization data — keep your call sites and objects clean

They’re all boxes, but they might have different labels. How do you handle such a case?

One Type, Different Property Values

Often times when creating a custom type, you’ll want to create many instances of that type with different initialization values. For example, if you’re modeling a Vehicle, you may want different vehicles with a different number of wheels, different colors, different body styles, etc…

To achieve this, we often make our initializers flexible by being able to pass in whatever value we want for each property we’re initializing. While there’s nothing wrong with this solution, it can lead to a lot of boilerplate code at call sites…

Understanding Extensions and Closures

Let’s extend a linked list with a forEach method

A clipboard with arbitrary text
A clipboard with arbitrary text
Lists, lists, everywhere a list

The goal

Create a method in a linked list that we can use to iterate over it and pass in code to do something with each position.

Linked Lists — A brief introduction

According to

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers…

In other words, a Linked List is like an array, but it’s stored using random access (pointers) rather than solid blocks of memory (contiguous memory locations). …

The case of the inseparable duo

What is a retain cycle? Why should I use weak? When do I use unowned?

What you’ll learn about in this article:

  • Memory Management
  • Automatic Reference Counting (ARC)
  • Retain Cycles
  • What strong vs. weak vs. unowned mean, and when to use them
A man holding an empty bird cage. Like an app holding a reference it doesn’t need to
A man holding an empty bird cage. Like an app holding a reference it doesn’t need to
Retain cycles cause your app to hold onto things it should let go of

Memory Management Introduced

In Software Development, memory management is a crucial aspect of an efficient, maintainable application. When we’re talking about Mobile Development, memory management is definitely crucial because our devices have fewer resources, and throttle those resources more often than their live-in counterparts. In the iOS world, poor memory management will cause the OS to kill your app if your app’s memory space reaches an unknown limit.

Memory is what we mostly use to temporarily store data in our app. If you…

Enums — encapsulating code ✅ modifying data ✅ doing it all cleanly ✅

Making a single enum containing US States with names, abbreviations, and an array of all of them

Map of Continental United States
Map of Continental United States
The map is missing a couple… but we won’t 😉

Our use-case

We’re building a shopping app for US customers. The requirements are such that we must use States and abbreviations in several places in our app, and it’s important that our spelling remains consistent. Sometimes we’ll need a single state’s name, sometimes we’ll need the state’s abbreviation — other times we’ll need both. Sometimes we’ll need an array of all of their names, other times we’ll need an array of all of their abbreviations. Finally, there are times where we’ll need both in an array so we can easily access either one in a list.

Let’s start with the basics

Most times I see enums used…

How to limit a variable in Swift

Follow me, and we’ll put a vise on a variable!

Over the years, I’ve had a few instances where I needed to limit the potential of a variable. For instance, maybe I have a shopping app and I need to limit the maximum price of any given item. You may be surprised to learn that there’s no built-in way to tackle this in the Swift Standard Library. There are many solutions, but most come with glaring caveats.

Let’s start with a use-case

I have a UICollectionView. In this collectionView, I only want to display a maximum of 2 cells. This collection view’s count is based on an array that could have thousands of entries. …

How to refactor without hurting yourself

… and passing a closure

Kenny Dubroff

I’m a Full Stack iOS Developer with a passion for writing clean, reusable code.

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