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 trialMeedo Al
iOS Development Techdegree Student 2,203 PointsMerging Two Dictionaries Error
Hello there,
Am trying to proceed with this project, so I've created a dictionary holding each player's information, I've also created a wholistic array filled with each player's dictionary, & then I've created an empty dictionaries for each team to start filling them by players.
however when I try to add to dictionaries to each other, I get compiler error
if I used the notion += between the two dictionaries I get this error:
Binary Operator "+=" cannot be applied to two [String : String] operands
while if I used the function extend or append, I get this error:
value of type '[String : String]' has no member 'extend' or value of type '[String : String]' has no member 'append'
I don't know how to merge two dictionaries or add them to each other?
2 Answers
garyguermantokman
21,097 PointsOne suggestion is to Map over the key/values in the first dictionary and add them to the second dictionary. Hope this helps!
var dict1 = ["Name": "Gary", "AnotherName": "Bob"]
var dict2 = ["Website": "TreeHouse"]
dict1.map { key, value in
dict2[key] = value
}
Pavel Fomchenkov
20,897 PointsYou aren't supposed to use map, filter, and reduce yet.