Skip to content

Instantly share code, notes, and snippets.

@iAmWillShepherd
Created June 17, 2022 19:18
Show Gist options
  • Save iAmWillShepherd/d011b0a9d1fce3c8a1fe70d25b5db394 to your computer and use it in GitHub Desktop.
Save iAmWillShepherd/d011b0a9d1fce3c8a1fe70d25b5db394 to your computer and use it in GitHub Desktop.
How to return a closure from a function.
func greetingMaker(greeting: String)  -> (String) -> String {
  return {
      "\(greeting), \($0)"
  }
}

let hello = greetingMaker(greeting: "Hello")

hello("world") // "Hello, World"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment