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

I initialize AVCaptureDeviceInput. In Swift 2, instead of getting an NSError variable, you catch the error with a do-try-catch sandwich. However, I do not see how to get an NSError inside the catch part. The recommendation on the Apple Developer Forum does not indicate how you can access NSError.

Can someone enlighten me?

+7
exception-handling swift2 error-handling avcapturedevice
source share
1 answer

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 } 

I hope it will be useful

+21
source share

All Articles