Skip to content

Instantly share code, notes, and snippets.

@LTe
Forked from krodak/SubclassEquality.playground
Last active March 17, 2016 11:03
Show Gist options
  • Save LTe/51075e63b7aa840c3361 to your computer and use it in GitHub Desktop.
Save LTe/51075e63b7aa840c3361 to your computer and use it in GitHub Desktop.
class EventFeed: Hashable, Equatable {
var eventId = 0
var hashValue : Int { return eventId }
func equals(another: EventFeed) -> Bool {
return self.eventId === another.eventId
}
}
func ==(lhs: EventFeed, rhs: EventFeed) -> Bool {
return lsh.equals(rhs)
}
class PostUpload : EventFeed {
var postId : Int
override var hashValue : Int { return postId }
init(id: Int) {
postId = id
}
func equals(another: EventFeed) -> Bool {
return self.postId === another.posttId
}
}
var postQueue = [PostUpload]()
let importantPost = PostUpload(id: 12)
postQueue.append(PostUpload(id: 10))
postQueue.append(importantPost)
//this should be 1, not 0
let index = postQueue.indexOf(importantPost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment