1

I'm trying to get the hourly forecast from the Wunderground API but my code returns this error. I am interested in the forecast humidity for a specific hour of the day from the Wunderground API for a research project.

  let currenttt       = jsonResult["current_observation"] as NSDictionary
  let currentttv       = currenttt["display_location"] as NSDictionary
  let c: String!      = currentttv["city"] as NSString

this code works perfectly on http://api.wunderground.com/api/0c5ad177d8c2e097/conditions/q/CA/San_Francisco.json but what I need to add in order to obtain the Humidity in different hours.

I am trying to get the information of icon, I understand that it depends of the hour or other value that I need to add in order to get a specific “icon”.

let urlAsString "http://api.wunderground.com/api/0c5ad177d8c2e097/forecast/q/CA/San_Francisco.json"

let w       = jsonResult["hourly_forecast"] as NSDictionary
let f       = w["FCTTIME"] as NSDictionary
let a: String!      = f["icon"] as NSString

the error is “The operation couldn’t be completed. (NSURLErrorDomain error -1001.)fatal error: unexpectedly found nil while unwrapping an Optional value(lldb) “

and “Thread 10: EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT,subcode=0xe7ffdefe)”

RenzoG
  • 31
  • 5
  • Welcome to SO! What error are you getting? Could you post that together with your question? – Timusan Jan 11 '15 at 03:16
  • I am trying to get the information of icon, I understand that it depends of the hour or other value that I need to add in order to get a specific “icon”. let urlAsString "http://api.wunderground.com/api/0c5ad177d8c2e097/forecast/q/CA/San_Francisco.json" let w = jsonResult["hourly_forecast"] as NSDictionary let f = w["FCTTIME"] as NSDictionary let a: String! = f["icon"] as NSString the error is “The operation couldn’t be completed. (NSURLErrorDomain error -1001.)fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)“ – RenzoG Jan 13 '15 at 01:14

1 Answers1

0
if let a = f["icon"] { print(a) }  

//prints 'mostly cloudy'

No need to cast 'a' as an NSString. String type is inferred.

Michael Castro
  • 314
  • 4
  • 14