Вот код, который я хочу, чтобы преобразовать из Swift2.3 в Swift3:Переход от Swit2.3 к Swift3 делу «Нагрузочный с неперехваченного исключением типа NSException»
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)
})
}
})
Определение 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)
А вот Swift3 версия:
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")
}
}
Определение 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)
Подробнее:
Когда я запускаю этот код на Swift 2.3 работает нормально, но когда я запускаю его в Swift 3, когда он добраться до этой линии
AWSCloudLogic.defaultCloudLogic().invokeFunction(functionName, withParameters: parameters) { (result : Any?, error: Error?) in
Он получает текущую ошибку:
libc++abi.dylib: terminating with uncaught exception of type NSException
Нет никакого другого описания!