Using Type-Safe Identifiers in Swift

Nicely does it

Steven Curtis
3 min readMay 3, 2021
Photo by Agung Raharja on Unsplash

Before we start

Difficulty: Beginner | Easy | **Normal** | Challenging

This article has been developed using Xcode 12.4, and Swift 5.3.2

This is supported by the YouTube video

Prerequisites:

Why

You need to uniquely identify both values and objects — and this is often brought into focus when you are using Core Data in your project.

If you want to keep track of instances of your value types, you can use an `Identifier` in much the same way that you might use ObjectIdentifier for class-types (well, objects).

You may well be able to do this through UUID, but using your own Identifier gives you more flexibility, and allows you to make your code type-safe which may well be particularly important when using databases (for example CoreData abstractions).

--

--