Nathan McKaskle Nathan McKaskle - 3 months ago 7x
Swift Question

Swift 2.0 Call Can Throw but is not marked with try

I'm trying to update the code in my app after the update to XCode 7 and it looks like I'm going to have to go through a serious learning curve again just to catch up. What am I doing wrong in the code below?

Is if let still being used?

enter image description here

I am so not familiar with try/catch outside of C#. I don't know how to use it in the context of swift and it'd be great to find an easy to understand guide that doesn't assume that I ever knew Objective C or have ever come across this before.


Use this instead:

do {
    let json = try NSJSONSerialization.JSONObjectWithData(...)
    return json
} catch let error as NSError {
    print("JSON Error: \(error.localizedDescription)")