Post

Replies

Boosts

Views

Activity

Swift Code Example using map inside of forEach
This looks like it should work but it doesn't: let str = "SOME SEARCH TEXT" var thing = String() let letters = ["A","E","S"] let replacements = ["a", "e", "s"] letters.enumerated().forEach { (i,r) in thing = String(str.map {$0 == Character(String(r)) ? Character(String(replacements[i])) : $0}); print(thing) } I want the looped changes to persist but only the last iteration does. Any ideas? TIA, SC
4
0
619
Mar ’22