Closure has no parameter, no return type
var closureEmpty:()->() = {
print("no parameter, no return")
}
print(closureEmpty())
Alternative to do the same thing
var closeEmpty1:()->Void={
print("no parameter, no return")
}
closeEmpty1()
Cloesure has no parameter, but return type
var clousre:()->String{
return "hi"
}
Pass closure as parameter in Swift
func fun(num:Int, closure:(Int)->(Int)){
print(closure(num))
}
var closePara:(Int)->(Int)={
return $0*20
}
fun(num:10, closure:closePara)
Trailing Closure Syntax in Swift
It means Closure is the last parameter to the function
func tailClosure(num:Int, closure:()->()){
print("Hello")
closure()
}
tailClosure(num:3){
print("Closure Block code")
}