Last active
October 24, 2025 07:36
-
-
Save dterekhov/5fc71a9230f7f1786da85e71c9513eb2 to your computer and use it in GitHub Desktop.
Map to unwrap an optional value #tip #swift-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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
commented
Oct 17, 2025
Author

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