Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//: Playground - noun: a place where people can play
import Cocoa
protocol Account: Hashable {
var accountID: String {get}
var hashValue: Int {get}
}
// https://twitter.com/optshiftk/status/628985834801336320
func ==<T: Account>(lhs: T, rhs: T) -> Bool {
return lhs.accountID == rhs.accountID
}
class FooAccount: Account {
let accountID = "foo"
let hashValue = 1
}
class BarAccount: Account {
let accountID = "bar"
let hashValue = 2
}
let foo = FooAccount()
let bar = BarAccount()
var accounts = Set<Account>()
accounts.insert(foo)
accounts.insert(bar)
// Two errors on line 32:
// protocol type 'Account' does not conform to protocol 'Hashable' because 'Account' is not declared @objc
// protocol 'Account' can only be used as a generic constraint because it has Self or associated type requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment