gpt4 book ai didi

swift - 'connection(_:didReceive:)' 的使用不明确

转载 作者:行者123 更新时间:2023-11-28 06:19:57 26 4
gpt4 key购买 nike

static let didReceiveResponseSelector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)) as (NSURLConnectionDataDelegate) ->(NSURLConnection,URLResponse) -> ())

此代码返回错误:

Ambiguous use of 'connection(_:didReceive:)'

我在 GitHub 上引用了 Apple 的官方 evolution 线程,我尊重语法但不起作用:

Referencing the Objective-C selector of a method

最佳答案

NSURLConnectionDataDelegate 是一种协议(protocol),您不能使用 NSURLConnectionDataDelegate.connection(_:didReceive:) 创建选择器,您必须使用 NSURLConnectionDataDelegate 的实现,例如:

class YourDelegateImplementation: NSURLConnectionDataDelegate {
public func connection(_ connection: NSURLConnection, didReceive data: Data) {
}
}

然后你可以像这样创建一个选择器:

let yourDelegate: YourDelegateImplementation = YourDelegateImplementation()
let yourSelector : Selector = #selector(yourDelegate.connection(_:didReceive:))

关于swift - 'connection(_:didReceive:)' 的使用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43941670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com