Skip to content

Instantly share code, notes, and snippets.

@mmar
Created February 3, 2023 12:33
Show Gist options
  • Save mmar/db7a07f25c2fb6631ba488369593f402 to your computer and use it in GitHub Desktop.
Save mmar/db7a07f25c2fb6631ba488369593f402 to your computer and use it in GitHub Desktop.
Swift optional pattern matching in a for-in loop
// Source: https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#grammar_optional-pattern
let arrayOfOptionalInts: [Int?] = [nil, 2, 3, nil, 5]
for case let number? in arrayOfOptionalInts {
print("Found a \(number)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment