Created
August 5, 2014 07:28
-
-
Save cwagdev/c48fc0c8d8ebbd21dff6 to your computer and use it in GitHub Desktop.
Swift - Array Extension for .any
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
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