Reputation: 146
static let didReceiveResponseSelector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)) as (NSURLConnectionDataDelegate) ->(NSURLConnection,URLResponse) -> ())
This code is returning error:
Ambiguous use of 'connection(_:didReceive:)'
I referred to the official evolution thread of Apple on GitHub, I respected the syntax but is not working:
Referencing the Objective-C selector of a method
Upvotes: 1
Views: 356
Reputation: 146
solved, just add "?":
static let didReceiveResponseSelector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)) as ((NSURLConnectionDataDelegate) -> (NSURLConnection,URLResponse) -> void)?)
Upvotes: 0
Reputation: 42479
Don't cast the Selector:
let didReceiveResponseSelector = #selector(NSURLConnectionDelegate.connection(_:didReceive:))
It's also worth noting that the delegate function connection(_ connection: NSURLConnection, didReceive challenge: URLAuthenticationChallenge)
has been deprecated in favor of connection(_ connection: NSURLConnection, willSendRequestFor challenge: URLAuthenticationChallenge)
.
Upvotes: 0
Reputation: 229
NSURLConnectionDataDelegate
is a protocol, you can't create a Selector using NSURLConnectionDataDelegate.connection(_:didReceive:)
, you must used an implementation of NSURLConnectionDataDelegate like :
class YourDelegateImplementation: NSURLConnectionDataDelegate {
public func connection(_ connection: NSURLConnection, didReceive data: Data) {
}
}
And then you can create a Selector like this :
let yourDelegate: YourDelegateImplementation = YourDelegateImplementation()
let yourSelector : Selector = #selector(yourDelegate.connection(_:didReceive:))
Upvotes: 1