Implementation of ‘Equatable’ cannot be automatically synthesized in an extension in a different file to the type

Pushpendra Singh
1 min readMay 25, 2021

We use the “Equatable” protocol very commonly during our programming. We mostly use it where every we want to compare for equality.

It is very useful protocol in swift but we might have not observed a different behaviour of it. Question arise is what I am taking about.

What we generally follow for Equatable

struct Person {  var name: String?
var age: Int?
}
extension Person: Equatable {}

And we are done. We can check for the Equitability of model and get to know if they are not equal.

What if we write this extension into a different file?

struct Game {  var name: String?
var age: Int?
}
extension Person: Equatable {}

you will see the below error prompt out.

Ideally, It should have worked the way it has worked in the same file but it did not!

Reason why could be the ->

since these conformances need access to private stored members, perhaps same-file is the correct restriction to apply here because of which it is not able auto-synthesis the implementation

If you like the content please comment, 👏 and leave feedback.

Stay tuned for more in Swift 👍.

--

--