Last active
December 16, 2015 21:14
-
-
Save brentsimmons/beba6ec62302dfe09070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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