Mastering Equatable, Comparable, and Hashable in Swift

When building applications in Swift, you constantly need to compare objects, sort arrays, or store unique items in a Set or Dictionary. To do this efficiently, Swift relies on three fundamental protocols: Equatable, Comparable, and Hashable. While these protocols are easy to adopt, their behavior differs significantly depending on whether you are using a struct or a class. Let’s break down why we need them and how to implement them correctly. ...

June 29, 2026 · 5 min

Demystifying Optionals in Swift: ?, !, and Under the Hood

Swift is fundamentally designed to be a safe language, and one of its core safety features is how it handles the absence of values. In many languages, trying to access a null value leads to unexpected crashes. Swift solves this elegantly using Optionals. However, the differences between normal variables, Optionals (?), and Implicitly Unwrapped Optionals (!) often trip developers up. Let’s break down how they work, the dangers of misusing them, and even look under the hood by building our own Optional type from scratch. ...

June 29, 2026 · 4 min

Understanding Opaque Types in Swift and SwiftUI: The Power of `some`

If you have ever written a single line of SwiftUI, you have seen this code: var body: some View { Text("Hello, World!") } That tiny word—some—represents one of the most powerful and complex features introduced in modern Swift: Opaque Return Types. But what exactly does some do? Why can’t we just return View? And when should you use opaque types in your own non-UI Swift code? Let’s break down the what, why, where, and the common violations. ...

June 30, 2026 · 7 min