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 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!