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

John Wilcox
John Wilcox
4,233 Points

What on earth does this mean??

'cannot subscript a value of type '[String]' with an index of type '

Honestly. I can't figure out what is going on. Can someone please advise? I did my optional bindings and am trying to access the Actors array. Ugh.

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 film = movieDictionary["Spectre"] {
  if let castArray = film["cast"]{
    leadActor = castArray[0] {

    }
  }

}

1 Answer

Hey John,

You almost got it. Just remove the opening and closing braces after you set the leadActor. Not sure why you put them there.

John Wilcox
John Wilcox
4,233 Points

Oh man. Yep that would explain it. Thanks sir,