I recently released an app written 100% in SwiftUI and in doing so, uncovered some patterns that are difficult to express. In this post, I am going to explain how to set initial state in SwiftUI. It’s trickier than you’d expect.

First, an overview

There are three types of local state in SwiftUI:

  1. State that’s only controlled by this view
  2. State that’s only controlled by a parent
  3. State that’s controlled by both this view and its parent

There’s also external state with environment variables and observables, but I’m going to ignore these in this post for brevity.

State controlled by this view

If you have some local state…

This is part 2 of a series in writing an elegant and extensible network stack in Swift. You can read part 1 here.

Writing your own networking stack is easy! One of the main advantages of owning your stack is that it’s simple to add additional features. You can pick and choose what you add depending on the specific needs of your application. You don’t need your stack to support every feature anyone could think of, but if you own your code, you can easily add in features when appropriate.

In this post, I’ll show a few examples of extending…

Apple constantly updates their networking APIs to make them easier to use. However, I find that a lot of people still are hesitant to write their own networking layer and choose to rely on common open source solutions.

Writing your own networking stack has several benefits. To name just a few:

  • Avoids a 3rd party dependency which will need upgrading
  • More understandable code (since you wrote it!)
  • More extensible
  • Easier to debug, add logs, and add performance monitoring
  • Much easier to add advanced functionality
  • Allows you to parse errors from your backend into a specific model
  • Makes it easy to…

Offline mode is no longer just an extra feature you could choose to add to your app — it’s something many users expect. I’ve often seen developers force their favorite offline solution on a problem that could be solved in a better way.

There are many different ways of making an app work offline, each with advantages and drawbacks. There’s no magic bullet that will work every time, so it’s up to you to carefully weigh your options. Sometimes, the best solution may be a combination of several different technologies!

The main solutions available to make the app work offline…

In the card game ‘Bullshit’ (aka ‘Cheat’ or ‘BS’), players can lie about their cards for an advantage. Calling someone’s bluff is risky — if you’re wrong, then you’re punished. Players aren’t incentivised to call bullshit on someone else because it incurs too much personal risk.

I wanted to dive into the game theory of ‘Bullshit’ so I wrote a short application to simulate the game. I coded several different strategies, played them against each other thousands of times, and worked out the win rate of each strategy.

You can try playing against the best strategies yourself here. It’s tough…

Backend engineers know exactly what’s going on with their services. They know their QPS, memory footprint, error rate, and CPU utilization in real time. They even get paged automatically if there’s a critical error so they can respond quickly. Unfortunately, iOS engineers usually only have crash reporting and maybe some product metrics. Usually, we learn about bugs when a user reports it, or worse, when a user posts a bad review. We can do better.

Reporting Assertions

Assertions are conditional checks that ensure that your code is working as expected. Likely, you already have a few in your codebase. They check conditions…

This post is about one of my favorite brainteasers. I love it for two reasons:

  1. It has a surprising but understandable solution.
  2. It makes you consider what it means to be rational and logical.

The puzzle has a logical solution, but wanted to test whether actual humans would come to that solution by simulating the puzzle in real life with seven participants. But first, if you haven’t heard it before, you should spend some time to solve it yourself.

The Puzzle

Seven pirates have 100 gold coins to split amongst themselves. They have chosen an interesting way of splitting the pot.

  1. The…

Likely, your app’s onboarding experience isn’t very good. This isn’t because your product isn’t well designed or easy to learn; it’s because building successful onboarding experiences is just hard.


A couple of months ago, my chess puzzle app was struggling to retain new users. I loved the app, and many of my users did too, but, most people who downloaded the app wouldn’t use it more than once. So, I decided to build an onboarding experience for all the lost users.

Today’s users are more discerning than ever, have more options, and have shorter attention spans. When you look at…

HORSE may seem like a simple backyard game, but, surprisingly, there is a strategy which improves your chance of winning — and it probably isn’t what you’d expect.

HORSE is a popular basketball game where players take turns attempting the same shot. With two players, the game works like this:

  1. Player A attempts any basketball shot.
  2. If they make it, then player B has to make the exact same shot. Otherwise, it’s player B’s possession.
  3. If player B misses, they acquire a letter. Either way, Player A gets to shoot again.
  4. Letters are acquired in order: H-O-R-S-E. Once a player…

At Superhuman, we’re building the fastest email experience in the world.

This post describes several techniques to debug closed source libraries such as UIKit.

As we’ve pushed iOS to its limits, we’ve found some inscrutable runtime bugs. In order to solve these, we’ve had to dive into the deepest internals of UIKit.

Since UIKit is closed source, we can’t place breakpoints or view the code. However, as we’ll see, nothing in Objective-C is really private.

In this post, we’ll cover:

  • Reading private variables
  • Swizzling to see property changes
  • Watching memory to observe instance variable changes

Most of these examples are…

Peter Livesey

Coder, traveler and nerd. I also eat and drink.

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