使用开关满足多个约束之一
你可以创建一个元组并使用如下所示的开关:
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")
}