Last active
October 24, 2025 07:38
-
-
Save dterekhov/99afc72eded0db526729151728f9a2a6 to your computer and use it in GitHub Desktop.
Filtering and unwrapping optionals in a sequence with `for case let` #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 filtering and unwrapping optionals in a sequence with `for case let`. | |
| // Equivalent to `compactMap`, but shows pattern matching directly in the loop. | |
| let strings: [String?] = ["pizza", nil, "cola"] | |
| for case let string? in strings { | |
| print(string) // pizza, cola | |
| } |
dterekhov
commented
Oct 17, 2025
Author


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