What a great invention! With closures you can put the code where together where it belongs and there is no need to pepper your code with little helper functions.

Here are some things you can do with closures:

brush: swift
func loadData(completion : (result : Int, success : Bool) -> (Void)) {
  completion(3, true)
}

loadData() {
   result, success in

   if success {
     print("Success! The data was \(result)"
   }
   else {
   print("Failure!")
}

Comment