Conforming to Hashable protocol?

You're missing the declaration:

struct DateStruct: Hashable {

And your == function is wrong. You should compare the three properties.

static func == (lhs: DateStruct, rhs: DateStruct) -> Bool {
    return lhs.year == rhs.year && lhs.month == rhs.month && lhs.day == rhs.day
}

It's possible for two different values to have the same hash value.


    var hashValue: Int 

is obsolete (except in the legacy NSObject inheritance trees).

    func hash(into hasher: inout Hasher)
    {
        hasher.combine(year);
        hasher.combine(month) 
    ...

is the swiftlely modern way to hash your way in class.

And per rmaddy answer above "==" operator also has to have kinks ironed out to be correct for your semantics.

Per Manish you get Hashable comformance for structs for free just declaring that.


If the class has fields of type (another class), that class should adopt Hashable.

example

struct Project : Hashable {
    var activities: [Activity]?

}

Here, Activity class must adopt Hashable too.