7. Closures
This concept might look like a weird one. Do not worry, you'll understand it eventually, and I will keep it simple here.
Swift allows us to define a function just like a Data Type like Int , String, etc. It means you can define and use functions like constants or variables. These functions are called closures.
On a different note, closures themselves are anonymous functions or functions with no name, they are essentially a self-contained package of functionality that we can pass around and use.
A simple example could be:
let printHello = {
print("Hello World!")
}You can call it just like a function:
//calling closure...
printHello()Last updated
Was this helpful?