I keep getting the following error when trying to extend Collection
in Swift:
Cannot subscript a value of type 'Self' with an index of type 'Int'
Here is my code:
extension Collection {
func random() -> Element {
let randomIndex = count.arc4random
return self[randomIndex]
}
}