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 2.0 Collections and Control Flow Control Flow With Conditional Statements Working with Switch Statements

Im stuck on this question any help

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Mohammad Rehman,

To do this you're going to use a switch statement and switch on the key. For cases where the key is a European country, append the value (not the key!) to the europeanCapitals array. For keys that are Asian countries, append the value to asianCapitals and finally for the default case, append the values to otherCapitals.

for (key, value) in world {
// we need to use a switch statement inside this loop, and pass on the value for key
    switch key {
        // now for each case we will assign what code to execute when the key is matched
        // adds to europeanCapitals array
        case "BEL", "LIE", "BGR": europeanCapitals.append(value)
        // adds to asianCapitals array
        case "IND", "VNM": asianCapitals.append(value)
       // adds all remaining capitals to otherCapitals array
        default: otherCapitals.append(value)
       // we use the default case because switch statements MUST be exhaustive
    }
}

Hope this helps, good luck!