2017-05-12 6 views
0
static let didReceiveResponseSelector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)) as (NSURLConnectionDataDelegate) ->(NSURLConnection,URLResponse) ->()) 

이 코드는 반환 오류 :모호한 사용

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

내가 GitHub의에 애플의 공식 진화 스레드에 언급, 나는 구문을 존중하지만 아니다 작업 :

Referencing the Objective-C selector of a method

+0

불행하게도,'as' 주조로 명확하게하는 것은 프로토콜에 선언 된 방법이 작동하지 않습니다. [this thread] (http://stackoverflow.com/q/39221563/6541007)를 확인하십시오. – OOPer

답변

0

해결, 단지 추가 :

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

NSURLConnectionDataDelegate은 프로토콜, 당신은 NSURLConnectionDataDelegate.connection(_:didReceive:)를 사용하여 선택기를 만들 수 없습니다, 당신은 NSURLConnectionDataD의 구현을 사용합니다 같은 elegate :

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

을 그리고 당신은이 같은 선택기 만들 수 있습니다

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

아니오 (NSURLConnectionDataDelegate.connectionDidFinishLoading (_ :) –

+0

모습을 작동하지 그래서 다른 대의원 가능 : 데이터 –

0

가 선택기 캐스팅하지 마십시오 : 그것은 주목할 가치가

let didReceiveResponseSelector = #selector(NSURLConnectionDelegate.connection(_:didReceive:)) 

을 그 위임 기능 connection(_ connection: NSURLConnection, didReceive challenge: URLAuthenticationChallenge) 더 이상 지원되지 않습니다. connection(_ connection: NSURLConnection, willSendRequestFor challenge: URLAuthenticationChallenge) "?"

+0

가 미안 해요 didReceive 데이터에 대한 선택이 필요를 너무 이것에 대해 가능해야하고, 코드가이 #selector에서 –

+0

당신은 NSURLConnectionDataDelegate와 NSURLConnectionDelegate 사이에 혼란스러워합니다. –