ios - 在 Swift 3 中为闭包定义类型别名

标签 ios swift swift3

我正在尝试像这样在 swift 3 中为闭包定义类型别名:

 public typealias URLRequestClosure = (response: URLResponse?, data: Data?, error: Error?) -> Void

我得到一个错误,我应该在参数名称前加上下划线。 IE: public typealias URLRequestClosure = (_ response: URLResponse?, _ data: Data?, _ error: Error?) -> Void 谁能解释我为什么?这与 Swift 3 有关吗?

非常感谢

最佳答案

您不能在闭包类型别名中指定参数名称。所以不是:

public typealias URLRequestClosure = (response: URLResponse?, data: Data?, error: Error?) -> Void

你应该使用:

public typealias URLRequestClosure = (URLResponse?, Data?, Error?) -> Void

关于ios - 在 Swift 3 中为闭包定义类型别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40183806/

相关文章:

swift - void 函数中出现意外的非 void 返回值 (Swift 3)

swift 3 : Method expecting variadic String parameter can only receive single String argument

ios - 尝试使用 Alamofire 在 Swift 3 中解析 JSON

ios - 如何使 NSOperationQueue 序列化?

swift - 主线程上的 BlockOperation 的 start()

ios - 单元测试电子邮件 注册 Firebase

ios - 尝试制作一个带有解析的笔记应用程序

swift - 在 MacOS 上将 EAGLContext 与 CIContext 结合使用

ios - 是否可以在 iOS 上设置 Crashlytics 而无需在每个开发人员的工作站上安装该应用程序?

ios - Swift:TextView 字体在模拟器和 iPhone 中的行为不同