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 trial

iOS Enumerations and Optionals in Swift Introduction to Optionals Nil Values in Collections

I can't figure out how it wants this nested optionals

i have tried:

if var movie = movieDictionary["Spectre"], var castList = movie["cast"] { var leadActor = list[0] } and : if var movie = movieDictionary["Spectre"], var castList = movie["cast"], var leadActor = castList[0]

and none of these have worked. When trying the first one it tells me that something isn't right with the array subscript. When trying it the other way, it tells me that I don't have the right variable name or something.

optionals.swift
let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "Lรฉa Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]

var leadActor: String = ""

// Enter code below
if var movie = movieDictionary["Spectre"], var castList = movie["cast"] {
  var leadActor = list[0]
}

1 Answer

Never mind. I was stupid and didn't notice that a variable of leadActor was already created in the challenge