Satisfy one of multiple constraints using switch

suggest change

Match a tuple of optionals. Swift 2 spelled the case .Some. Swift 3 and later use .some.

let str: String? = "hi"
let x: Int? = 5

switch (str, x) {
case (.some, .some):
    print("Both have values")
case (.some, nil):
    print("String has a value")
case (nil, .some):
    print("Int has a value")
case (nil, nil):
    print("Neither has a value")
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents