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 trialAlex Ferguson
2,518 PointsData modeling with structures challenge 2 of 2
Retrieve the language used for iOS development by using the relevant key and dictionary subscripting notation and store it in a variable named iosLanguage.
this is what i wrote i dont know whats wrong with it though
let languages = ["iOS": "Swift", "Android":"Java"]
var iosLanguage: String = ["iOS: Swift"]
1 Answer
Stone Preston
42,016 Pointsyou need to use dictionary subscripting notation. dictionary subscripting looks like this
dictionaryName["key"]
and it will return the value stored for that key.
in this challenge we have an dictionary called languages with 2 key value pairs. the key for the first pair is "iOS" and the value is "Swift". this is the key value pair you need. we can get the value for the key "iOS" using
languages["iOS"] // returns "Swift"
so to retrieve the language used for iOS and then store it in a variable you would use
let languages = ["iOS": "Swift", "Android":"Java"]
var iosLanguage = languages["iOS"] // variable now has "Swift" as its value