Satisfy one of multiple constraints using switch

suggest change

You can create a tuple and use a switch like so:

var str: String? = "hi"
var 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 have values")
}

Feedback about page:

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



Table Of Contents