Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Swift的“switch”语句中使用带范围的“case”_Swift_Switch Statement - Fatal编程技术网

在Swift的“switch”语句中使用带范围的“case”

在Swift的“switch”语句中使用带范围的“case”,swift,switch-statement,Swift,Switch Statement,我是斯威夫特的新手,在斯威夫特操场上测试一些东西。试图使用开关,但它不起作用。有人能帮我吗 func loveCal() { let loveScore = Int.random(in: 0...100) switch loveScore { case 80...100: print("You love eachother like Kanye loves Kanye") case 40...80: print("You go t

我是斯威夫特的新手,在斯威夫特操场上测试一些东西。试图使用
开关
,但它不起作用。有人能帮我吗

func loveCal() {
    let loveScore = Int.random(in: 0...100)

    switch loveScore {
    case 80...100:
        print("You love eachother like Kanye loves Kanye")
    case 40...80:
        print("You go together like coke and mentos")
    case 0...40:
        print("You'll be forever alone")
    }
}

loveCal()

您缺少的只是
默认值
情况:

// ...
case 0...40:
    print("You'll be forever alone")
default:
    print("This should never happen")

您在Xcode中遇到了什么错误?你必须在操场上的指纹旁边有一条消息。
switch Int.random(在:0…100){case 0。。