I\'m trying to become familiar with the new do catch statements with swift 2 and iOS 9
My problem is that when an error occurs with NSURLSession, the da
This is because catch only catches what a functions "throws".
NSJSONSerialization throws, but force unwrapping an empty Optional doesn't, it always crashes.
Use if let or the new guard function to safely unwrap your values.
do {
if let myData = data, let jsonResult = try NSJSONSerialization.JSONObjectWithData(myData, options: []) as? NSDictionary {
print(jsonResult)
}
} catch {
print(error)
}