相关疑难解决方法(0)

将NSDictionary转换为Dictionary Swift

我已经看到这在其他问题中得到了解决 - 但我认为因为这个NSDictionary是通过下标访问的,所以它会抛出一些错误.

func pickRandomRecipe(arrayOfRecipes: NSArray) -> Dictionary<String,Any> {
let randomRecipeIndex = Int(arc4random_uniform(UInt32(arrayOfRecipes.count)))

//Could not cast value of type '__NSDictionaryI' (0x7fbfc4ce0208) to 'Swift.Dictionary<Swift.String, protocol<>>' (0x7fbfc4e44358)
let randomRecipe: Dictionary = arrayOfRecipes[randomRecipeIndex] as! Dictionary<String,Any>
return randomRecipe
}
Run Code Online (Sandbox Code Playgroud)

dictionary casting subscript ios swift

2
推荐指数
1
解决办法
6113
查看次数

标签 统计

casting ×1

dictionary ×1

ios ×1

subscript ×1

swift ×1