Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Last active October 11, 2021 16:08
Show Gist options
  • Save deathlezz/dd53e42b8ee285e09d1eadca46a97d11 to your computer and use it in GitHub Desktop.
Save deathlezz/dd53e42b8ee285e09d1eadca46a97d11 to your computer and use it in GitHub Desktop.
Simple use of closures in Swift 5.
//
// Simple use of closures
//
// basic closure
let basic = {
print("I like pizza.")
}
basic() // I like pizza.
// accepting parameters
let accepting = { (place: String) in
print("I am going to \(place).")
}
accepting("Edinburgh") // I am going to Edinburgh.
// returning values
let returning = { (place: String) -> String in
return "I am going to \(place)."
}
print(returning("Edinburgh")) // I am going to Edinburgh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment