Instead of guard the data
parameter handle the error
returned in the completion handler.
If there is no error
then data
can be safely unwrapped.
let task = session.dataTaskWithURL(shotsUrl!, completionHandler: {
(data,response,error) -> Void in
if error != nil {
// do proper error handling
} else {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
...
And add also appropriate error handling in the catch
scope. It seems to be annoying but can be very useful. 😉
solved Unexpectedly found nil while unwrapping an optional value while reading JSON [closed]