Here is the code I want to convert from Swift2.3 to Swift3:
AWSCloudLogic.defaultCloudLogic().invokeFunction(functionName,
withParameters: parameters, completionBlock: {(result: AnyObject?, error: NSError?) -> Void in
if let result = result {
dispatch_async(dispatch_get_main_queue(), {
print("CloudLogicViewController: Result: \(result)")
//self.activityIndicator.stopAnimating()
//self.resultTextView.text = prettyPrintJson(result)
})
}
var errorMessage: String
if let error = error {
if let cloudUserInfo = error.userInfo as? [String: AnyObject],
cloudMessage = cloudUserInfo["errorMessage"] as? String {
errorMessage = "Error: \(cloudMessage)"
print(errorMessage)
} else {
errorMessage = "Error occurred in invoking the Lambda Function. No error message found."
print(errorMessage)
}
dispatch_async(dispatch_get_main_queue(), {
print("Error occurred in invoking Lambda Function: \(error)")
//self.activityIndicator.stopAnimating()
//self.resultTextView.text = errorMessage
let alertView = UIAlertController(title: NSLocalizedString("Error", comment: "Title bar for error alert."), message: error.localizedDescription, preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: NSLocalizedString("Dismiss", comment: "Button on alert dialog."), style: .Default, handler: nil))
self.presentViewController(alertView, animated: true, completion: nil)
})
}
})
Definition of Swift2.3:
/**
Invokes the specified AWS Lambda function and passes the results and possible error back to the application asynchronously.
@param name AWS Lambda function name, e.g., hello-world
@param parameters The object from which to generate JSON request data. Can be `nil`.
@param completionBlock handler for results from the function
*/
public func invokeFunction(name: String, withParameters parameters: AnyObject?, completionBlock: (AnyObject, NSError) -> Void)
And here is Swift3 version:
AWSCloudLogic.defaultCloudLogic().invokeFunction(functionName, withParameters: parameters) { (result : Any?, error: Error?) in
if let result = result{
print(result)
}
if let error = error{
print(error)
print("error")
}else{
print("No error but issue")
}
}
Definition of Swift3:
/**
Invokes the specified AWS Lambda function and passes the results and possible error back to the application asynchronously.
@param name AWS Lambda function name, e.g., hello-world
@param parameters The object from which to generate JSON request data. Can be `nil`.
@param completionBlock handler for results from the function
*/
open func invokeFunction(_ name: String, withParameters parameters: Any?, completionBlock: @escaping (Any, Error) -> Swift.Void)
More detail:
When I run this code on Swift 2.3 it works fine but when I run it in Swift 3 when it get to this line
AWSCloudLogic.defaultCloudLogic().invokeFunction(functionName, withParameters: parameters) { (result : Any?, error: Error?) in
It gets current error:
libc++abi.dylib: terminating with uncaught exception of type NSException
There is no other description!