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

Dickson Cheung
Dickson Cheung
2,573 Points

Nil Value in Collections - Challenge

i'm having problems with this challenge

let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "Léa Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]

var leadActor: String = ""

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

I'm trying to pull Daniel Craig's name but everytime i run the program I'm getting Error: Make sure you are calling array [0] - there's no compiler error so i'm not sure where i'm going wrong here

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 let movie = movieDictionary["Spectre"], 
  let castList = movie["cast"] { 
  let leadActor = castList[0]
  }

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Dickson! You're doing just fine. You have one extraneous let. The variable leadActor is already set up for you so you just need to reassign the appropriate string. Long story short? Remove the let before leadActor and your code passes!

Hope this helps! :sparkles: