Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Switch Statements

can somebody go into more detail about this? How do we know which ones append to which arrays? I'm lost

can somebody give me some tips on where to start

operators.swift
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 {
    "europeanCapitals": will have values of 


}

3 Answers

Stuart Wright
Stuart Wright
41,100 Points

Do you need help with the code/logic, or just the locations of the capitals? If the latter: the first three are European, the next three are 'other', and the last two are Asian. Append the appropriate capitals (which are the dictionary values) to the arrays, rather than the countries (which are the keys).

I need help with the code and logic

Stuart Wright
Stuart Wright
41,100 Points

The idea is that you create a switch statement, where you are switching on the key, and depending on which case that key satisfies, append the corresponding value to your chosen array. Here's the syntax to get you started, demonstrating the logic for European capitals:

for (key, value) in world {
    // Enter your code below
    switch key {
      case "BEL", "BGR", "LIE" : europeanCapitals.append(value)
      // Insert other cases here

    }
    // End code
}