从Swit2.3到Swift3的转换会导致“以类型为NSException的未捕获异常终止".

编程入门 行业动态 更新时间:2024-10-08 22:49:41
本文介绍了从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的未捕获异常终止".

本文发布于:2023-11-26 19:16:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   类型   NSException   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!