Reputation: 9660
I have a function displayForPhone and displayForPrinter which does not have any parameters. I want to return those functions from another function called "display". I have the following code in Swift Playground but it just says there is an error but never tells me what the error is:
func displayForPrinter() {
println("Displaying for printer")
}
func displayForPhone() {
println("Displaying for phone")
}
func display:(shouldDisplayForPhone :Bool) -> (void) -> (void) {
return shouldDisplayForPhone ? displayForPhone : displayForPrinter
}
Upvotes: 1
Views: 447
Reputation: 24714
Chang your code to this
func displayForPrinter() {
println("Displaying for printer")
}
func displayForPhone() {
println("Displaying for phone")
}
func display(shouldDisplayForPhone :Bool) -> (Void) -> (Void) {
return shouldDisplayForPhone ? displayForPhone : displayForPrinter
}
//test
let function = display(true)
function()
Upvotes: 5