Using Clousers in Swift

Hello guys in this tutorial I am going to tell you about Clousers.

Clousers are used as an alternative to functions. 

According to Apple , Clousers are self contained blocks of functionality that can be passed around or used in the code. 

Syntax for Clousers in Swift

              Syntax ==  {(parameters) -> (returnType) in }


Here is an example for Clousers : 




Here var clouserExample is the declaration of the clouser
and print is its usage. 


Difference between functions and Clousers : 

Most of the people ask what is the difference between functions and Clousers. Although they offer almost the same purpose but here are some of the key points : 


       FUNCTION
  • has a name 
  • has func keyword
  • has no in keyword

  • CLOSURE
  • has no name
  • has no func keyword
  • has in keyword




And that's it. Hope you have enjoyed the blog !
Thanks :)












Comments

Post a Comment

Popular Posts