Skip to content

Instantly share code, notes, and snippets.

@brentsimmons
Last active December 16, 2015 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentsimmons/beba6ec62302dfe09070 to your computer and use it in GitHub Desktop.
Save brentsimmons/beba6ec62302dfe09070 to your computer and use it in GitHub Desktop.
//: 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