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

Jonathan Law
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Law
iOS Development Techdegree Student 6,824 Points

Challenge task using switch with keys and values... can't understand the error

I completed this task but was unable to solve. Checked previous questions pertaining to this task and was encouraged to find that my code matched another's solution code, only I had forgotten to include the closing "curly brace" for the code I added. I was overjoyed, but even after adding the closing curly brace my code will not solve the task.

All solutions that are posted in previous questions seem to have the same code (as my present solution), unless I have missed something despite combing over these three or four lines for a half an hour!

switch.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 {
    // Enter your code below
    switch key {
    case "BEL","LIE","BGR":europeanCapitals.apend(value)
    case "IND","VNM":asianCapitals.apend(value)
    default:otherCapitals.apend(value)
 }   

    // End code
}

1 Answer

David Papandrew
David Papandrew
8,386 Points

You have a typo in your code. ".apend" should be ".append"

Add the missing "p" in each statement needing the .append and you should be set.