如您所见,我是编码新手。
我正在尝试在开关盒上打印正确的星期几。但是我不能。我的代码有什么问题?
var aNumber = Int.random(in: 0...10)
func dayOfTheWeek(day: Int) {
switch dayOfTheWeek {
case ..<2:
print ("Monday")
case ..<3:
print ("Tuesday")
case ..<4:
print ("Wednesday")
case ..<5:
print ("Thursday")
case ..<6:
print ("Friday")
case ..<7:
print ("Saturday")
case ..<8:
print ("Sunday")
default:
print("Error")
}
print(aNumber)
}
dayOfTheWeek(day: aNumber)
dayOfTheWeek是函数,而day是Int。因此,您必须在整数之间切换。
尝试switch day {...}
。
用switch dayOfTheWeek {
替换switch day {