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

Hello. This challenge is very confusing for someone who is new and trying to learn. I don't understand what to write.


This is very confusing. These challenges feel like you go from learning basic to syntax to apparently comprehending its use case and how it should be written. In other words, I feel you go from 1-1500 with respect to finishing the video and being presented with this.

As a matter of record, the video examples all use print, and we print to the console, and then here you're suddenly appending an array but don't write much code or see much code with that happening before you get here. I understand we've been through arrays, and appending as separate tasks but to then have to combine them in this way really throws you off.

I honestly have very little idea what to write or how to express it. Any help would be much appreciated.

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

    // End code

1 Answer

Dave Faliskie
Dave Faliskie
17,793 Points

It definitely can be hard to try and connect ideas together, but once you do your learning is so much more valuable. That being said take the problem one step at a time. I normally will open up a play ground for something like this and try and solve it there because you can see what's going on a bit better.

First thing I would do is create a switch statement on the key (the question tells you to do this)

switch key {
case "SOME CASE":
// do something
// do something
// do something

Once you have that, you know you have 3 different outcomes for each of the countries in the world array - either sort to europeanCapitals, asianCapitals, or otherCapitals. So you can modify the above to to do the sorting and place each value in the proper array.

Definitely seeing a large question like this can be overwhelming but the answers are normally pretty simple once you break it down into smaller parts - that's generally true for everything!

This should hopefully get you on the right track let me know if you still need help