Re-implement if let in Swift

Write your own!

Steven Curtis
The Startup

--

Photo by Hannah Busing on Unsplash

I’ve previously re-implemented Optionals in Swift. What if we were to do the same with if let?

Are you along for this ride?

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

and the following would be nice to have

  • Be able to use closures in Swift (guide HERE)
  • Use Generics in Swift (guide HERE)

Terminology

Closure: A self-contained block of functionality that can be passed around

Generics: Reusable functions and types that can work with any type (or subset of a certain type

Optional: Swift introduced optionals that handle the absence of a value, simply by declaring if there is a value or not. An optional is a type on it’s own!

Optional Binding: Using an if let pattern to unwrap an optional safely

String: A collection of Characters, commonly thought of as a word or sentence

Optional Binding: If let in Swift

--

--