Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Swift 2.1, how do you get the NSError that was thrown?

I'm initializing an AVCaptureDeviceInput. In Swift 2 rather than getting an NSError variable you catch an error with a do-try-catch sandwich. However I don't see how to get the NSError inside the catch part. The recommendation given on Apple's developer forum does not indicate how you can access the NSError.

Can someone enlighten me?

like image 687
CommaToast Avatar asked Nov 17 '15 05:11

CommaToast


1 Answers

This worked for me:

 var error: NSError?

        do {
            request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(jsonString, options: [])
        } catch let error1 as NSError {
            error = error1
            request.HTTPBody = nil
        }

Hope this will be helpful

like image 85
Karlos Avatar answered Nov 16 '22 03:11

Karlos