Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,120 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,120 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
}