Listing 10.5 Updating a value

let oldRating: Int? = movieRatings.updateValue(5, forKey: “Donnie Darko”)
if let lastRating = oldRating, currentRating = movieRatings[“Donnie Darko”] {
print(“Old rating: (lastRating); current rating: (currentRating)”)
}

I don’t understand this part. Isn’t oldRating being assigned to a value of ‘5’ in the first line, since you are updating it?

The return value of updateValue is actually the original value (which they named oldRating), not the updated value. See the paragraph on the page before the listing that starts with 'This method is useful because it gives you a handle on the last value … '.

Thank you. Yeah I saw that, I guess I was just confused initially because it seemed like it was assigning it to the updated value. I guess I will just have to keep it in my head that it’s the old value even though just looking at it confuses me a bit.

Thanks!:slight_smile: I was wondering about the same thing as AgentGandhi.