Skip to content

Instantly share code, notes, and snippets.

@dterekhov
Last active October 24, 2025 07:36
Show Gist options
  • Select an option

  • Save dterekhov/5fc71a9230f7f1786da85e71c9513eb2 to your computer and use it in GitHub Desktop.

Select an option

Save dterekhov/5fc71a9230f7f1786da85e71c9513eb2 to your computer and use it in GitHub Desktop.
Map to unwrap an optional value #tip #swift-api
// Demonstrates how `map` can be used to unwrap an optional value and execute code if it exists.
var string: String? = "maybe"
// This...
if let string {
print(string)
}
// Becomes...
string.map { print($0) }
@dterekhov

Copy link
Copy Markdown
Author

AB1C4EC5-F6BF-4E96-BC78-BC89214420E6_1_105_c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment