Skip to content

Instantly share code, notes, and snippets.

@dlo
Forked from brentsimmons/protocolequatable.swift
Created August 5, 2015 19:17
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 dlo/5a90699d46daece04074 to your computer and use it in GitHub Desktop.
Save dlo/5a90699d46daece04074 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
protocol AccountLike: Equatable {
var accountID: String {get}
}
class Account : AccountLike {
let accountID = nil
}
// https://twitter.com/optshiftk/status/628985834801336320
func ==<T: AccountLike>(lhs: T, rhs: T) -> Bool {
return lhs.accountID == rhs.accountID
}
class FooAccount: Account {
let accountID = "foo"
}
class BarAccount: Account {
let accountID = "bar"
}
let foo = FooAccount()
let bar = BarAccount()
var accounts: [Account] = [Account]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment