无法在带有参数列表的Swift 2中调用'sendAsynchronousRequest' [英] Cannot invoke 'sendAsynchronousRequest' in Swift 2 with an argument list

查看:105
本文介绍了无法在带有参数列表的Swift 2中调用'sendAsynchronousRequest'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在重写我的Swift 1.2代码的一部分,以与Swift 2.0兼容.实际上,我无法弄清楚对"sendAsynchronousRequest"进行了哪些更改-当前我的所有请求均失败

I'm currently rewriting parts of my Swift 1.2 code for compatibility with Swift 2.0. Actually I cannot figure out what changes are made to "sendAsynchronousRequest" - currently all my requests fail

NSURLConnection.sendAsynchronousRequest(request, queue: queue, completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in})

无法使用类型为参数的列表调用'sendAsynchronousRequest' '(NSURLRequest,队列:NSOperationQueue,complementHandler: (NSURLResponse !, NSData !, NSError!)->无效)'

Cannot invoke 'sendAsynchronousRequest' with an argument list of type '(NSURLRequest, queue: NSOperationQueue, completionHandler: (NSURLResponse!, NSData!, NSError!) -> Void)'

你有什么主意吗?

推荐答案

在Swift 1.2和Xcode 6.3中,sendAsynchronousRequest:queue:completionHandler:的签名为:

With Swift 1.2 and Xcode 6.3, the signature of sendAsynchronousRequest:queue:completionHandler: is:

class func sendAsynchronousRequest(request: NSURLRequest,
    queue: NSOperationQueue!,
    completionHandler handler: (NSURLResponse!, NSData!, NSError!) -> Void)

但是,在Swift 2和Xcode 7 beta中,sendAsynchronousRequest:queue:completionHandler:的签名已更改,现在为:

With Swift 2 and Xcode 7 beta, however, the signature of sendAsynchronousRequest:queue:completionHandler: has changed and is now:

// Note the non optionals, optionals and implicitly unwrapped optionals differences
class func sendAsynchronousRequest(request: NSURLRequest,
    queue: NSOperationQueue,
    completionHandler handler: (NSURLResponse?, NSData?, NSError?) -> Void)

因此,转到Swift 2和Xcode 7 beta,您将不得不更改completionHandler参数的实现,并确保queue参数是非可选的.

As a consequence, turning to Swift 2 and Xcode 7 beta, you will have to change your completionHandler parameter implementation and ensure that your queue parameter is a non optional.

这篇关于无法在带有参数列表的Swift 2中调用'sendAsynchronousRequest'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆