Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIan Henderson
5,512 PointsTried challenge w/ 2 different coding approaches that both work in XCode. Both cases get "could not be compiled" error.
The error says to check "preview" for compiler errors, but in both cases there is no text in the "preview" view. One approach is attached, the other is as follows:
let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "LĂ©a Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]
if let movieName = movieDictionary["Spectre"], let movieTeam = movieName["cast"] { var leadActor: String = movieTeam[0] }
let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "LĂ©a Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]
if let movieName = movieDictionary["Spectre"] , let leadRole = movieName["cast"]{
var leadActor: String = leadRole[0]
}
1 Answer
Jorge Solana
6,064 PointsHey Ian
Variable leadActor is already written on top of the code challenge, so you don't need to define it again in the if let section. Xcode works because it should declare a local variable to the if statement.
Other than that, I don't see any other issue.
Keep up the good work!