Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 1.09 KB

Day7.md

File metadata and controls

26 lines (18 loc) · 1.09 KB

Day 7 - HackingWithSwift - 100DaysOfSwiftUI Challenge

Energy and persistence conquer all things - Benjamin Franklin

Closures - Part II

Today I learnt about:

  • Using closures as parameters when they accept parameters
  • Using closures as parameters when they return values
  • Shorthand parameter names (ie: $0 and $1)
  • Closures with multihand parameters
  • Returning closures from functions
  • Capturing values from closures

The summary of the entire day was:

  • You can assign closures to variables, then call them later on.
  • Closures can accept parameters and return values, like regular functions.
  • You can pass closures into functions as parameters, and those closures can have parameters of their own and a return value.
  • If the last parameter to your function is a closure, you can use trailing closure syntax.
  • Swift automatically provides shorthand parameter names like $0 and $1, but not everyone uses them.
  • If you use external values inside your closures, they will be captured so the closure can refer to them later.

That's All for the Day 7 of 100DaysOfSwiftUI!