Last active
October 11, 2021 16:08
-
-
Save deathlezz/dd53e42b8ee285e09d1eadca46a97d11 to your computer and use it in GitHub Desktop.
Simple use of closures in Swift 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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