Recent articles

Jump to a random post

Faking network responses in tests

Published on: October 21, 2019

Modern applications often rely on data from a network connection to work as intended. Sometimes they rely heavily on the network and are almost worthless without an internet connection while other apps can function mostly fine without a network connection. What these apps have in common is that they contain code that might be challenging to write tests for. Whenever you write unit tests, you should always strive to make your tests as predictable, reproducible and most importantly independent of external factors as possible. This is a huge difference compared to integration testing where you’d test a certain part of...

Read more...

An in-depth look at for loops in Swift

Published on: October 16, 2019

In Swift, there is more than one way to loop over a list of elements. If we only consider the loops that aren't intended to create new lists or have side effects, you end up with two types of loops that are very similar; forEach and for item in list, or the for loop. In this week's Quick Tip, I will explain the difference between for and forEach loops, and you I will show some examples that should help you make a decision picking one of either loop methods, depending on your needs. Understanding for loops Commonly when you write...

Read more...

Optimizing Your Application’s Reviews

Published on: October 14, 2019

We all love the idea of getting loads of App Reviews, preferably with five stars and a description that explains why our apps are amazing. Unfortunately, users often don’t take the time to reviews the apps they enjoy. Instead, users will review your app when they’re unhappy. If something about your app doesn’t please them or something doesn’t work as expected, they will happily write an angry review and rate your app one star. So how do we get people to review apps when they are happy so they give us five stars? That’s exactly what I would like to...

Read more...

What is Module Stability in Swift and why should you care?

Published on: October 7, 2019

The Swift team has recently released Swift 5.1. This version of the Swift language contains many cool features like Function Builders that are used for SwiftUI and Property Wrappers that can be used to add extra functionality to properties. This release also contains a feature called Module Stability. But what is this feature? And what does it mean to you as a developer? In this week’s blog post, I will explain this to you. But before we get to Module Stability, let’s do a little time traveling back to Swift 5.0, which shipped with ABI (Application Binary Interface) Stability. Understanding...

Read more...

Finding the difference between two Arrays

Published on: October 6, 2019

Many applications work with data, often they are built to retrieve data and display this data to the user in a table view, collection view, list (if you're using SwiftUI) or a different kind of component. It's not uncommon for this data to change and when it does you might be interested in figuring out what elements were added to the data and which items were removed. This isn't always straightforward so up until now you might have written code something like the following: func didFetchNewRecipes(_ newRecipes: [Recipe]) { recipes = newRecipes tableView.reloadData() } Simple and effective, much easier than...

Read more...

Getting started with unit testing your Swift code on iOS – part 2

Published on: October 2, 2019

In part 1 of this two-part blog post, you’ve learned how to write synchronous unit tests for a login view model. As a reminder, you saw how to implement tests for the following requirements: When both login fields are empty, pressing the login button should trigger an error that informs the user that both fields are mandatory. When one of the two fields is empty, pressing the login button should trigger an error that informs the user that the empty field is mandatory. When the user’s email address does not contain an @ symbol, pressing the login button should trigger...

Read more...

Getting started with unit testing your Swift code on iOS – part 1

Published on: September 30, 2019

Recently, I ran a poll on Twitter and discovered that a lot of people are not sure how to get started writing tests, or they struggle to get time approved to write tests for their code. In this blogpost, I will take you through some of the first steps you can take to start writing tests of your own and help you pave the way to a more stable codebase. Why bother with tests at all? You might be wondering why you should bother with code that tests your code. When you put it like that, the idea might indeed...

Read more...

Supporting Low Data Mode in your app

Published on: September 23, 2019

Together with iOS 13, Apple announced a new feature called Low Data Mode. This feature allows users to limit the amount of data that’s used by apps on their phone. The low data mode setting is available in the settings app. Whenever a user is on a slow network, a very busy network or on a network that might charge them for every megabyte they download, users might not want to spend their limited data budget on large fancy images or clever prefetching logic. With Low Data Mode, users can now inform your app that they are on such a...

Read more...

Spend less time maintaining your test suite by using the Builder Pattern

Published on: September 16, 2019

Often when we write code, we have to initialize objects. Sometimes the object’s initializer doesn’t take any arguments and a simple let object = MyObject() call suffices to create your object, other times things aren’t so simple and you need to supply multiple arguments to an object’s initializer. If you have read my previous post, Cleaning up your dependencies with protocols , you might have refactored your code to use protocol composition to wrap dependencies up into a single object that only exposes what’s needed to the caller. In this blogpost I would like to show you a technique I...

Read more...

Cleaning up your dependencies with protocols

Published on: September 9, 2019

If you’re into writing clean, testable and maintainable code you must have come across the term “Dependency Injection” at some point. If you’re not sure what dependency injection is, that’s okay. I will explain it briefly so we’re all on the same page before we get to the main point of this post. Dependency Injection in a Nutshell Dependency injection is the practice of making sure that no object creates or manages its own dependencies. This is best illustrated using an example. Imagine you’re building a login page for an app and you have separate service objects for registering a...

Read more...