2016-12-07 7 views
-1

스위프트 3에서 고정 방법에 폐쇄 유형을 오버로드 할 수 있습니까? 예를 들어, 나는이 방법으로 구조체가 :Swift 3에서 클로저 시그니처로 정적 메서드에 과부하를 걸 수 있습니까?

struct Some { 
    static func doSomething(first: String, @escaping completion: ([Int]?) -> Void) { 
    ... 
    } 

    static func doSomething(first: String, @escaping completion: ([Int]?, String?) -> Void) { 
    ... 
    } 
}

을하지만 난이 ( 매개 변수를 사용하여 클로저) 첫 번째 방법 Some.doSomething(first: "Hello") { (numbers) in ... }를 호출 할 때 컴파일러는 나에게 오류 제공 :

Ambiguous use of 'doSomething(first:completion:)'

+2

나는 competip 매개 변수를 지정하는 것이 좋습니다. Some.doSomething (first : "Hello") {(numbers : [Int]?) -> Void in ...} – Bruce0

+0

@ Bruce0 네, 효과가있었습니다. 도와 줘서 고마워! – Dmitrue

답변

2

Yes you can overload static method by closure type in Swift 3, but you need to specify the type of the parameter for the first function as its parameters partially matches with that of second function