Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make a type `Identifiable` based on its `Hashable` hash value.
/**
Make a type `Identifiable` based on its `Hashable` hash value.
This can be useful when all the properties are required to represent its identifier.
```
struct Item: Hashable, IdentifiableByHashable {
let title: String
var message: String?
}
```
*/
public protocol IdentifiableByHashable: Identifiable {}
extension IdentifiableByHashable where Self: Hashable {
public var id: Int { hashValue }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment