切换到快速编译但永远运行

时间:2017-06-23 15:23:30

标签: swift switch-statement swift-playground

即时学习swift atm和switch语句是迄今为止最棘手的部分。

以下代码可以简单地计算数组中的每个投票数,我希望它由交换机(!)完成。

我的问题:

  1. 为什么游乐场会永远运行? (重启几次)
  2. 是重要的导入基础吗? (该行不是我的代码)
  3. 我更感兴趣的是它为什么不起作用以及它是如何工作的,而不是真正在正确的代码中。我很高兴,但任何帮助!

        import UIKit
    enum SchoolMascotOption {
        case salamander, marmot, neither
    }
    import Foundation
    let mascotVotes: [SchoolMascotOption] = [.neither, .marmot, .salamander, .neither, .marmot, .neither, .neither, .marmot, .neither, .salamander, .salamander, .marmot, .neither, .neither, .salamander, .neither, .neither, .marmot, .salamander, .neither, .neither, .neither, .marmot, .marmot, .neither, .neither, .marmot, .salamander, .neither, .marmot, .marmot, .marmot, .marmot, .neither, .salamander, .salamander, .salamander, .salamander, .salamander, .salamander, .salamander, .marmot, .neither, .salamander, .salamander, .neither, .salamander, .neither, .salamander, .salamander, .salamander, .salamander, .salamander, .salamander, .marmot, .neither, .neither, .marmot, .salamander, .neither, .neither, .salamander, .salamander, .neither, .salamander, .salamander, .salamander, .salamander, .neither, .salamander, .neither, .salamander, .marmot, .salamander, .marmot, .salamander, .salamander, .marmot, .salamander, .neither, .marmot, .marmot, .marmot, .salamander, .marmot, .salamander, .marmot, .neither, .marmot, .neither, .salamander, .marmot, .marmot, .marmot, .neither, .marmot, .marmot, .salamander, .neither, .neither, .salamander, .neither, .neither, .marmot, .neither, .salamander, .salamander, .salamander, .neither, .neither, .salamander, .salamander, .salamander, .marmot, .salamander, .salamander, .marmot, .salamander, .neither, .marmot, .marmot, .neither, .neither, .salamander, .marmot, .neither, .marmot, .salamander, .salamander, .marmot, .salamander, .neither, .salamander, .marmot, .neither, .salamander, .marmot, .marmot, .salamander, .marmot, .salamander, .marmot, .salamander, .salamander, .marmot, .marmot, .neither, .marmot, .neither, .marmot, .salamander, .salamander, .salamander, .neither, .salamander, .salamander, .neither, .marmot, .neither, .marmot, .marmot, .marmot, .marmot, .neither, .marmot, .neither, .salamander, .marmot, .salamander, .neither, .salamander, .salamander, .marmot, .neither, .marmot, .neither, .salamander, .neither, .salamander, .neither, .neither, .marmot, .salamander, .neither, .marmot, .salamander, .marmot, .neither, .salamander, .neither, .neither, .salamander, .salamander, .salamander, .neither, .salamander, .neither, .marmot, .salamander, .marmot]
    
    var salamanderCounts = 0
    var marmotCounts = 0
    var neitherCounts = 0
    
    for vote in mascotVotes {
    
        switch vote {
        case .salamander :
            salamanderCounts += 1
        case .marmot :
            marmotCounts += 1
        case .neither :
            neitherCounts += 1
        }
    }
    print(salamanderCounts)
    print(marmotCounts)
    print(neitherCounts)
    

    screenshot

    谢谢你们的帮助!!!

1 个答案:

答案 0 :(得分:0)

我想,在操场上跑步不会因为阵列的大小而闪电般快。

import Foundation import UIKit包括UIKit时{p> Foundation是多余的(尽管在这个游乐场中不需要任何人)。

尝试将所有代码从操场中删除,等待操场不要说“正在运行”或类似的东西,然后将其粘贴回来。

如果这不能解决问题,请尝试将数组长五个元素,以确保长度不是问题。

祝你好运!