Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Playlist Browser with Swift Building the Music Library and Playlist Models Using a Playlist Instance

cannot assign a value of type "string!" to a value of type "string?"

I have some error in my code :

    title = playlistDictionary["title"] as! String!

cannot assign a value of type "string!" to a value of type "string?"

I tried many possibilities but i don't find the solution :(

Sean Mateer
Sean Mateer
9,330 Points

I've been having some problems here as well. The error goes away if I use the following syntax, though I'm not entirely sure it's correct

title = playlistDictionary["title"] as? String

It seems as though swift has made some updates since this video was made. I'm on xcode 6.3.2.

2 Answers

Having the same problem. Hopefully someone knows the answer! :)

thomas lotocki
thomas lotocki
3,230 Points

This syntax works on my end no probs:

title = playlistDictionary["title"] as! String!