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 trialAman Kansal
2,966 Pointstitle = playlistDictionary["title"] as String! I am getting '(String, NSObject) is not convertible to String' error?
i have tried changing the code to
title = playlistDictionary["title"]! as? String
it was something i found on the internet but this also doesn't seem to work. please help!
4 Answers
Chris Shaw
26,676 PointsHi Aman,
Try the following instead as you're attempting to unwrap the dictionary value then down cast it which won't work in this case.
title = playlistDictionary["title"] as String
Hope that helps.
Aman Kansal
2,966 PointsHey Chris,
The original code I tried was:
title = playlistDictionary["title"] as String!
I also tried your code above and got the same error: '(String, NSObject)' is not convertible to 'String'
Would you have any other idea what could be happening?
HO WANG CHENG
8,694 PointsHi Aman
try
title = playlistDictionary["title"] as NSString
Rasmus Rønholt
Courses Plus Student 17,358 PointsI know this was asked a while ago... Anyways, I don't know if there is a Swift version discrepancy, but I don't understand why the speaker is unwrapping the result, when he is assigning it to an optional anyway - title:String? still needs to be unwrapped when accessed later. The following should work...
title = playlistDictionary["title"] as? String
Rasmus Rønholt
Courses Plus Student 17,358 PointsNb. Note the ? trailing 'as' which is the only difference to Chris' suggestion :)
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsHi, Chris,
Maybe you have another solution? I even installed old xcode 6.0.1, but still have that error. (String, NSObject) is not convertible to String.