Equatable and Hashable structures
Now that the Swift compiler automatically synthesizes Equatable
and Hashable
conformances for value types, it's easier than ever to setup model structures with nested types that are all Equatable
and Hashable
!
typealias Value = Hashable & Codable
struct User: Value {
var name: String
var age: Int
var lastLoginDate: Date?
var settings: Settings
}
extension User {
struct Settings: Value {
var itemsPerPage: Int
var theme: Theme
}
}
extension User.Settings {
enum Theme: String, Value {
case light
case dark
}
}