2017-09-05 78 views
0

在這裏,我試圖將不同的首都附加到他們的大陸地區。有人能告訴我我做錯了什麼嗎?在控制流中使用switch語句的問題。 Swift 3

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 
} 

回答

2

您需要在您的情況符合key,不worldvar沒有意義。

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 key { 
    case "BEL", "LIE", "BGR" : europeanCapitals.append(value); 
    case "VNM", "IND" : asianCapitals.append(value); 
    default: otherCapitals.append(value); 
    } 
    // End code 
}