It is because returnData!
is nil. If you put a break point at var dict
, run and then po returnData!
I believe you will find that to be true. And because the data at which NSJSONSerialization is trying to accept as a parameter is nil, it will be as well. I would go through your logic or your source to figure out why it is nil.
Also if you are using NSURLSession to retrieve your data - make sure you have a valid configured session before calling dataTaskWithURL. Like so...
var config = NSURLSessionConfiguration.defaultSessionConfiguration()
var session = NSURLSession(configuration: config)
var dataTask:NSURLSessionDataTask = session.dataTaskWithURL...
I ran into this problem and figured out that the session needed to be configured before I called the data task.
EDIT Also try this. Use optional binding.
if let data: NSDictionary = NSJSONSerialization.JSONObjectWithData(returnData, options: NSJSONReadingOptions.AllowFragments, error: nil) as? NSDictionary {
println("json = \(data)")
}
else {
println("returnData really is nil")
}