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

Sean Lafferty
Sean Lafferty
3,029 Points

ANY CLOSER?

Really struggling, been at this for 90 minutes! could really use a wee help! Please, Sean

operators.swift
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []

let world = [String: String] = [
  "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


    for key in world {

    switch value {

    case "BEL", "BGR", "LIE": europeanCapitals.updateValue()
    case "IND","VNM": asianCapitals.updateValue()
    default otherCapitals.updateValue()

    // End code
}

1 Answer

Garrett Votaw
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Garrett Votaw
iOS Development Techdegree Graduate 15,223 Points

Hey Sean,

So I noticed a few errors with your code.

Your code is missing a closing bracket for the switch statement and a colon for the default clause. In addition, you are currently switching on the value, when you really should be switching on the key. I see you are using a function called updateValue(), I'm not sure where that is defined but you may want to use the "append" function instead and pass in the value that you already have from the first for loop. Finally since the first for loop is giving your a value and a key already then you don't need to create a second for loop to get the key. You can simply switch on the key. You can check my solution below. Hopefully that is helpful! Happy Coding

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
    switch key {
      case "BEL", "LIE", "BGR": europeanCapitals.append(value)
      case "USA", "MEX", "BRA": otherCapitals.append(value)
      case "IND", "VNM": asianCapitals.append(value)
      default: break
    }
    // End code
}