As a learning exercise, I am trying to use a for-in loop to replace a String in an Array (with a dictionary value) if the String is an existing key in a Dictionary.  I already know how to do this using .stringByReplacingOccurrencesOfString, but I'd like to learn what I'm doing wrong here, and how to accomplish this with a for-in loop. 
let sillyMonkeyString = "A monkey stole my iPhone"
let dictionary = ["monkey": "🐒", "iPhone":"📱"]
var toArray = sillyMonkeyString.componentsSeparatedByString(" ")
// desired result is "A 🐒 stole my 📱"
Here is what doesn't work:
for var str in toArray {
    if let val = dictionary[str] {
        str = val                  
    }
}
let backToString = toArray.joinWithSeparator(" ")
What does work:
var newArray = [String]()
for var str in toArray {
    if let val = dictionary[str] {
        str = val
    }
    newArray.append(str)
}
let backToString = newArray.joinWithSeparator(" ")
This works because I'm creating a new array and appending to the new array.  However, my original Array is mutable, so why is the first solution not correctly assigning str to val in the original Array inside the for-in loop?  The only other related question I found here had a great one-line answer that did not explain whether or not I can accomplish this using a for-in loop. 
UPDATE: I do not recommend implementing a for-in loop for this particular use case. I asked this question to learn how to do this. If a user would like to replace parts of strings with a dictionary, I highly recommend considering using one of the more efficient and Swifty solutions below (which may not be the accepted solution)







for-inuse thereducefunction on the array.