Skip to content

Instantly share code, notes, and snippets.

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

  • Save dterekhov/99afc72eded0db526729151728f9a2a6 to your computer and use it in GitHub Desktop.

Select an option

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
// 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

Copy link
Copy Markdown
Author

92D76E6F-D8D4-482A-A8C8-F05E2AC9FBF1_1_105_c
7E4B84DB-F630-4CD4-832B-A9C0171D908E_1_105_c

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