sergdort / XcodeEquatableGenerator

Xcode 8 Source Code Extension will generate conformance to Swift Equatable protocol based on type and fields selection.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hashable instead?

seivan opened this issue · comments

Instead of Equatable, how about Hashable based on its content?
It would support being used in a Set and would use the same fields as the current implementation of Equatable supports.

Hi, @seivan I see your point.
But my concern is that not everybody needs Hashable for each type.
And there are several ways how to implement hashValue
If you think that there is a popular way, that we can generate, I'd love to see

I'm thinking, that as long as every property is hashable it's class could be as well.

If you're hashable, you're also going to be equatable. So why not?

I mean the popular way to generate hashValue is for example

struct Person: Hashable {
    var name: String
    var  age: Int
    var hashValue: Int {
          return name.hashValue ^ age.hashValue
    }
}

I wonder if its ok to generate it by default like this

If so, I would consider to make a separate xcode extension under this project which will generate Hashable conformance as well.

Because in my project for example we don't need Hashable for our domain objects

I tend to use OrderedSet (custom) and Set a lot for when uniqueness matters, but that could just be me.

Thanks for ^, I didn't actually know about that!

hi, @seivan, I have a implementation for this here, https://github.com/WANGjieJacques/CodeGenerator, this implementation is inspired by IntelliJ.