8️⃣Closures
Fall 2024 | Peter Bidoshi
func getData() -> String {
return "Fetched Data"
}// Same code from above
func getData() -> String {
return "Fetched Data"
}
// Save the string returned from the function in a variable
var data = getData()
// Print the variable
print(data)// This is the syntax to indicate that this
// function takes in another function!
// "handler" is just the name of the variable,
// and we can call it whatever we want
func getData(handler: (String) -> Void) {
handler("Fetched Data")
}Last updated
Was this helpful?