问:我在以下任务中收到错误“条件绑定的初始化程序必须具有可选类型,而不是‘字符串’”。
在这里查看我的代码:
let movieDictionary = [ "Spectre" : [ "cast" : [ "Daniel Craig" , "Christoph Waltz" , "Léa Seydoux" , "Ralph Fiennes" , "Monica Bellucci" , "Naomie Harris" ]]]
var LeadActor : String = "" // 在下面输入代码if let movie = movieDictionary [ "Spectre" ], let cast = movie [ "cast"],让演员=
演员[ 0 ] {
主角=演员}
答:似乎您正试图从键“强制转换”中获取值两次 - 这是正确的方法:
let movieDictionary = [ "Spectre" : [ "cast" : [ "Daniel Craig" , "Christoph Waltz" , "Léa Seydoux" , "Ralph Fiennes" , "Monica Bellucci" , "Naomie Harris" ]]]
var LeadActor : String = "" if let movie = movieDictionary [ "Spectre" ], let moviecast = movie [ "cast"] {主角=电影
[ 0 ]
}