Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashable instead? #1

Open
seivan opened this issue Oct 10, 2016 · 5 comments
Open

Hashable instead? #1

seivan opened this issue Oct 10, 2016 · 5 comments

Comments

@seivan
Copy link

seivan commented Oct 10, 2016

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.

@sergdort
Copy link
Owner

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

@seivan
Copy link
Author

seivan commented Oct 10, 2016

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?

@sergdort
Copy link
Owner

sergdort commented Oct 21, 2016

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

@seivan
Copy link
Author

seivan commented Oct 21, 2016

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!

@wangjiejacques
Copy link

wangjiejacques commented Jun 28, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants