Swift 3中是否可以通过闭包签名重载静态方法?
Is it possible to overload static method by closure signature in Swift 3?
是否可以在Swift 3中通过闭包类型重载静态方法?
例如,我有一个包含 2 个方法的结构:
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 ... }
(带有 one 参数的闭包)编译器给我一个错误:
Ambiguous use of 'doSomething(first:completion:)'
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
Some.doSomething(first: "") { (number:[Int]?) in
}
Some.doSomething(first: "") { (number, value) in
}
是否可以在Swift 3中通过闭包类型重载静态方法? 例如,我有一个包含 2 个方法的结构:
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 ... }
(带有 one 参数的闭包)编译器给我一个错误:
Ambiguous use of 'doSomething(first:completion:)'
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
Some.doSomething(first: "") { (number:[Int]?) in
}
Some.doSomething(first: "") { (number, value) in
}