在控制流中使用switch语句的问题。斯威夫特3

时间:2017-09-05 18:03:12

标签: swift control-flow

在这里,我试图将不同的首都追加到他们的大陆地区。有谁能告诉我我做错了什么?

var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []

let world = [
  "BEL": "Brussels", 
  "LIE": "Vaduz", 
  "BGR": "Sofia", 
  "USA": "Washington D.C.", 
  "MEX": "Mexico City", 
  "BRA": "Brasilia", 
  "IND": "New Delhi", 
  "VNM": "Hanoi"]

for (key, value) in world {
    // Enter your code below
    switch world {
    case "BEL", "LIE", "BGR" : var europeanCapitals.append(value);
    case "VNM", "IND" : var asianCapitals.append(value);
   default: var otherCapitals.append(value);
    }
    // End code
}

1 个答案:

答案 0 :(得分:2)

您需要匹配 public async Task AddSingleChoiseTest(SingleChoiseTest singleChoiseTest) { if (singleChoiseTest == null) throw new NullReferenceException("Test cannot be null."); if (!singleChoiseTest.IsValid()) { throw new ArgumentException("Test is not vaild."); } using (_context) { _context.SingleChoiseTests.Add(singleChoiseTest); await _context.SaveChangesAsync(); } } ,而不是key,而您案例中的world则无法理解。

var