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

Tijn-Pieter Koopman
Tijn-Pieter Koopman
4,128 Points

I am not sure what I am doing wrong here. Can someone help?

When I check this it says: Remeber to append the values from each case statement to the correct array. What do I do?

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 capital in world {
    switch capital {
    case "BEL", "LIE", "BGR": europeanCapitals.append(capital)
    case "IND", "VNM": asianCapitals.append(capital)
    default: otherCapitals.append(capital)

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,538 Points

Hi Tijn-Pieter Koopman

You are very close. The syntax is correct; however, the switch is not switching on the correct value. Remember, the dictionary contains key: value pairs, but right now you are trying to switch on the pair instead of just the key. With that in mind, when you are appending, you should also be appending the value to the new array.

I've provided a pretty detailed answer to a previous post if you'd like to have a look.

Nice work! :) :dizzy: