iOS Interview Guide: Equatable Protocol

Nitin Aggarwal
Swiftable
Published in
7 min readFeb 12, 2024

--

Level: Intermediate, Priority: Medium

Equatable protocol is not just a fundamental aspect of the Swift, but also a crucial topic to preparing for interviews. Be ready to prepare these questions for your iOS interviews as these are the most common questions for interviews.

Q1: What is the Equatable protocol?

A type that can be compared for value equality.

protocol Equatable

The Equatable protocol is used to provide a way to compare two instances of a type for equality. It requires you to implement the == operator, which defines how instances of your type (including custom types) should be compared for equality. This is particularly useful when you have custom types and you need to compare them in the code.

Q2: How do you make a custom type conform to the Equatable protocol? Explain with an example.

For example, you’re making an app (called Task Manager) that manages a list of tasks. You have a Task struct that represents a task with a title and a priority level.

In order to implement the feature to a new task, you may need to check the task with the same title is already exists or not in your list. You want to…

--

--

Nitin Aggarwal
Swiftable

Lead iOS Engineer, Mentor, Author, Writer; 📙 Released "iOS Interview Handbook" 🔗 topmate.io/nitinagam17/827990