So given the following code, how does one get a reference to a function that takes a parameter with a default value and invoke the reference with the default value?
class Test {
func doIt() { print("Done") }
func doIt(_ adjective: String = "better") {
print("Done \(adjective)")
}
}
let t = Test()
let fn1 = t.doIt as () -> Void
let fn2 = t.doIt as (String) -> Void
fn1() // Works
fn2() // Does not work; requires parameter
I also tried the following
let fn2 = t.doIt as (String?) -> Void
But that also does not work. Any ideas? I'd like to invoke fn2()
and get the printed result "Done better"