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 trialHunter Garrett
6,339 PointsReceiving 'Any Object?' is not convertible to ' NSDictionary'
Swift is suggesting I downcast the first line to
let currentWeather = weatherDictionary["currently" as! NSDictionary.
However, when I downcast that I get erros for the rest of the "as" instances...
CURRENT CODE:
let currentWeather = weatherDictionary["currently"] as NSDictionary
currentTime = currentWeather["time"] as Int
temperature = currentWeather["temperature"] as Int
humidity = currentWeather["humidity"] as! Double
precipProbability = currentWeather["precipProbability"] as Double
summary = currentWeather["summary"] as String
icon = currentWeather["icon"] as String
3 Answers
Laura Morgan
1,941 PointsDang. I am getting the same thing. Did you happen to figure it out?
Hunter Garrett
6,339 PointsUnfortunately I haven't :'(
Dominykas Semeklis
2,414 PointsTry adding ! with each as. I reckon this has changed when xcode was updated. My code:
init(weatherDictionary: NSDictionary) {
let currentWeather = weatherDictionary["currently"] as! NSDictionary
currentTime = currentWeather["time"] as! Int
temperature = currentWeather["temperature"] as! Int
humidity = currentWeather["humidity"] as! Double
precipProbability = currentWeather["precipProbability"] as! Double
summary = currentWeather["summary"] as! String
icon = currentWeather["icon"] as! String
}
Robert Edison
1,281 PointsI found you need to unwrap each value in that statement not just forecastURL
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completeHandler: { (location: NSURL!, response: NSURLRespones!, error: NSError!) ->Void
Nick DeMarco
2,219 PointsNick DeMarco
2,219 PointsAny luck with this? Found myself in the same situation just now. I'm pretty sure it's an issue with the line:
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL, completionHandler:...
xCode keeps prompting me to force a downcast on forecastURL with the syntax:
forecastURL!
which I think ultimately forces the dataObject to have a problem.
Not sure how to proceed.