As of Swift 1.2, Apple introduces Set collection type.
Set
Say, I have a set like:
var set = Set(arrayLiteral: 1, 2, 3, 4, 5)
In swift 3
extension Set { public func randomObject() -> Element? { let n = Int(arc4random_uniform(UInt32(self.count))) let index = self.index(self.startIndex, offsetBy: n) return self.count > 0 ? self[index] : nil } }