Created
February 3, 2023 12:33
-
-
Save mmar/db7a07f25c2fb6631ba488369593f402 to your computer and use it in GitHub Desktop.
Swift optional pattern matching in a for-in loop
This file contains 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
// 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