NSDictionary should be bound to [NSCopying: AnyObject]or in your case [String: AnyObject], and not used Any(since this is just a Swift construct).
NSDictionary.
typealias Recipe = [String: AnyObject] // or some other Recipe class
func pickRandomRecipe(recipes: [Recipe]) -> Recipe? {
if recipes.isEmpty { return nil }
let index = Int(arc4random_uniform(UInt32(recipes.count)))
return recipes[index]
}
, , :
extension Array {
func randomChoice() -> Element? {
if isEmpty { return nil }
return self[Int(arc4random_uniform(UInt32(count)))]
}
}
if let recipe = recipes.randomChoice() {
}