即时学习swift atm和switch语句是迄今为止最棘手的部分。
以下代码可以简单地计算数组中的每个投票数,我希望它由交换机(!)完成。
我的问题:
我更感兴趣的是它为什么不起作用以及它是如何工作的,而不是真正在正确的代码中。我很高兴,但任何帮助!
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)
谢谢你们的帮助!!!
答案 0 :(得分:0)
我想,在操场上跑步不会因为阵列的大小而闪电般快。
当import Foundation
import UIKit
包括UIKit
时{p> Foundation
是多余的(尽管在这个游乐场中不需要任何人)。
尝试将所有代码从操场中删除,等待操场不要说“正在运行”或类似的东西,然后将其粘贴回来。
如果这不能解决问题,请尝试将数组长五个元素,以确保长度不是问题。
祝你好运!