Recent articles

Jump to a random post

Swift’s typealias explained with five examples

Published on: January 2, 2020

Swift grants developers the ability to shadow certain types with an alternative name using the typealias keyword. We can use this feature to create tuples and closures that look like types, or we can use them to provide alternative names for existing objects. In this post, we'll look at five ways in which typealiases can help you write cleaner and better code. 1. Improving readability with type aliases Perhaps this is the most obvious yet also somewhat underused way to use a typealias. When you have a type in your code that is very long or deeply nested, you could...

Read more...

Reversing an Array in Swift

Published on: January 1, 2020

You can reverse an Array, and any other Collection in Swift using the reverse method. For example var input = [1, 2, 3] print(input) // [1, 2, 3] input.reverse() print(input) // [3, 2, 1] The code above takes an array (input) and reverses it in-place using the reverse() method. This only works if your array is mutable. If you want to reverse an immutable array that's defined as let, or if you don't want to alter the original input you can use reversed() instead of reverse(): var input = [1, 2, 3] print(input) // [1, 2, 3] var reversed =...

Read more...

Year in review: 2019

Published on: December 30, 2019

It's the end of the year, and that means that we should all take a little bit of time to reflect on the past year. Some people like to reflect on their past year in a very statistical manner, they set measurable goals and they decide whether they met their goals at the end of the year. Personally, I don't really set goals per year. I simply strive to do the best I can every year. In this post, I would like to reflect on how 2019 has been for me, and I will share some of my plans for...

Read more...

Getting ready to publish your app on the App Store

Published on: December 24, 2019

You've done all the work to build your app, your UI looks amazing, animations are smooth and you're ready to put your app in the hands of other people. Maybe you're even ready to start offering your app on the App Store! This is a huge achievement if you are currently at this stage in your development cycle, I would like to congratulate you. Being ready to ship your app is a huge accomplishment, especially if it's your first App. I still remember the excitement when I submitted my first app to the App Review team in App Store Connect...

Read more...

Dependency injection with Storyboards and Xcode 11

Published on: December 23, 2019

For years I have had a bit of a love and hate relationship with Storyboards. I love how easy they make it for me to set up my AutoLayout constraints, but they can quickly grow unwieldy and for large projects with multiple developers Storyboards are hard to use because of merge conflicts that occur when multiple developers update the UI. For personal projects, however, my Storyboards tend to be small enough to manage. And since I'm the only developer working on them I never have merge conflicts. Yet still, I've never been completely happy with them. The main reason for...

Read more...

Using compositional collection view layouts in iOS 13

Published on: December 22, 2019

Ever since iOS 6, developers have been able to use collection views and to build interesting custom layouts by subclassing the UICollectionViewLayout or UICollectionViewFlowLayout classes. I even wrote an article about building custom collection view layouts a while ago. Today, I would like to introduce you to a new way of defining collection view layouts called compositional layouts. We're going to build the two layouts shown in the following image: I will first show you how to build a simple grid layout, and from there we'll continue working our way towards the end result. Building a grid layout A very...

Read more...

Modern table views with diffable data sources

Published on: December 21, 2019

At WWDC 2019 Apple announced a couple of really cool features for table views and collection views. One of these cool features comes in the form of UITableViewDiffableDataSource and its counterpart UICollectionViewDiffableDataSource. These new diffable data source classes allow us to define data sources for collection- and table views in terms of snapshots that represent the current state of the underlying models. The diffable data source will then compare the new snapshot to the old snapshot and it will automatically apply any insertions, deletions, and reordering of its contents. In today's article, I will show you how to use UITableViewDiffableDataSource...

Read more...

Fetching and displaying data from the network

Published on: December 20, 2019

One of the topics that I could write dozens of posts on is networking. Making calls to a remote API to retrieve or persist data is something that is a key feature in many apps that are currently in the App Store. Some apps make extensive use of the network while others only need the network to retrieve data periodically. No matter how extensively your app uses the network, the patterns for using the network in a clean and appropriate manner are often (roughly) the same. I have written several posts on networking in the past: Architecting a robust networking...

Read more...

Architecting a robust networking layer with protocols

Published on: December 19, 2019

Both networking and protocols are topics that I could write dozens of posts on, and I would still have more ideas and examples left in my head. In today's article, I would like to combine the topics of networking and protocols and explain how you can design a robust networking layer for your app, that's 100% testable and mockable because everything down to the URLRequest is abstracted behind a protocol. Defining our goals Any time you're getting ready to write code, you should define your goals first. What are you writing? What problems are you trying to solve? This is...

Read more...

Installing multiple Xcode versions with xcversion

Published on: December 18, 2019

As a developer that uses Xcode on a daily basis for multiple projects, you sometimes need to use different versions of Xcode depending on the project you’re working on. Or maybe you want to try out the latest Xcode beta, for example right after Apple announced it after WWDC. One way to manage is to go to the Apple developer portal, searching for the version you need and download it. You download the .xip file, expand it (eventually, it takes a while) and then you can finally open Xcode. But then you realize you also have to rename it before...

Read more...