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!
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
Eduardo Calvachi6,049 Points
Quiz Question about equivalent ways of updating Dictionary
One of the quiz a question that comes up is wether the following statements are equivalent:
dict.updateValue("yetAnotherValue", forKey: 3) dict = "yetAnotherValue"
I would like to verify the reason why they are not equivalent,
They accomplish the same task, but have a different in implementation. I tested the return types on Xcode.
Is it because using updateValue method returns an optional(nil in this case) and adding an entry with subString notation just returns the String Value?
Per the Swift documentation, "Unlike a subscript... the updateValue(_:forKey:) method returns the old value after performing an update. This enables you to check whether or not an update took place."
Hope that helps!