1
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

JAL
  • 41,701
  • 23
  • 172
  • 300
SOUA Hamza
  • 146
  • 2
  • 10
  • Unfortunately, disambiguating with `as` casting does not work for methods declared in protocols. Please check [this thread](http://stackoverflow.com/q/39221563/6541007). – OOPer May 14 '17 at 02:47

3 Answers3

1

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:))
Dany Sousa
  • 229
  • 2
  • 16
0

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).

JAL
  • 41,701
  • 23
  • 172
  • 300
0

solved, just add "?":

    static let didReceiveResponseSelector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)) as ((NSURLConnectionDataDelegate) -> (NSURLConnection,URLResponse) -> void)?)
SOUA Hamza
  • 146
  • 2
  • 10