Last active
April 11, 2016 20:03
-
-
Save mikekavouras/ba741be6eb8562c8093ac9d8f4dc31a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UIKit | |
| struct Obj { | |
| let id: String | |
| init(id: String) { | |
| self.id = id | |
| } | |
| } | |
| extension Obj: Equatable {} | |
| func ==(lhs: Obj, rhs: Obj) -> Bool { | |
| return lhs.id == rhs.id | |
| } | |
| let one = Obj(id: "beep") | |
| let two = Obj(id: "beep") | |
| let three = Obj(id: "boop") | |
| var arr = [one, two, three] | |
| var uniq = [Obj]() | |
| for item in arr { | |
| guard uniq.indexOf(item) == nil else { | |
| continue | |
| } | |
| uniq.append(item) | |
| } | |
| print(uniq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment