Skip to content

Instantly share code, notes, and snippets.

@cwagdev
Created August 5, 2014 07:28
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 cwagdev/c48fc0c8d8ebbd21dff6 to your computer and use it in GitHub Desktop.
Save cwagdev/c48fc0c8d8ebbd21dff6 to your computer and use it in GitHub Desktop.
Swift - Array Extension for .any
extension Array {
var any: T? {
get {
if self.count > 0 {
let randomIndicie = arc4random_uniform(UInt32(self.count))
return self[Int(randomIndicie)]
} else {
return nil
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment