Reputation: 13
So, I just started learning swift yesterday, so bear with me. I'm working on closures. I have a very simple set of statements.
let myClosure = {
println("this is a simple test")
}
func showWork( closure : ()->() ) {
closure()
}
showWork(myClosure)
I know that I am doing something wrong because println isn't working in the xCode playground. Basically, I've created a simple closure and passed it to my function. But, println isn't printing. What am I doing wrong?
Upvotes: 0
Views: 108
Reputation: 504
Instead of () -> ()
write Void -> Void
. So the whole thing would look like this:
let myClosure = {
print("this is a simple test")
}
func showWork( closure : Void->Void ) {
closure()
}
showWork(myClosure)
Upvotes: 1