本文介绍了从Swit2.3到Swift3的转换会导致“以类型为NSException的未捕获异常终止".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我想从Swift2.3转换为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) }) } })Swift2.3的定义:
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)这是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的定义:
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)更多详细信息:
当我在Swift 2.3上运行此代码时,它可以正常工作,但是当我在Swift 3中运行该代码时,它到达此行
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它得到当前错误:
libc++abi.dylib: terminating with uncaught exception of type NSException没有其他描述!
推荐答案Swift 3支持刚刚发布,请重新下载MobileHub示例应用程序.检查它是使用v0.10模板生成的,该模板显示在顶部任何文件的注释中. console.aws.amazon/mobilehub/home
Swift 3 support has just been released, please download the MobileHub sample app again. Checking that it was generated with v0.10 template shown in any file's comments at the top. console.aws.amazon/mobilehub/home
更多推荐
从Swit2.3到Swift3的转换会导致“以类型为NSException的未捕获异常终止".
发布评论