I want to replace many characters in a string so it looks like the keyboard is moved a bit.
This is what the program executes: *qwertyuiopasdfghjklzxcvbnm mmmmmmmmmmmmmmmmmmmmmmmmmm *
Why does the program prioritize the last one always?
Can someone tell me why this is wrong and how to fix it
import UIKit
var str = "qwertyuiopasdfghjklzxcvbnm"
var replaced = str.replacingOccurrences(of: "m", with: "n").replacingOccurrences(of: "n", with: "b") .replacingOccurrences(of: "b", with: "v").replacingOccurrences(of: "v", with: "c") .replacingOccurrences(of: "c", with: "x").replacingOccurrences(of: "x", with: "z") .replacingOccurrences(of: "z", with: "l").replacingOccurrences(of: "l", with: "k") .replacingOccurrences(of: "k", with: "j").replacingOccurrences(of: "j", with: "h") .replacingOccurrences(of: "h", with: "g").replacingOccurrences(of: "g", with: "g") .replacingOccurrences(of: "g", with: "f").replacingOccurrences(of: "f", with: "d") .replacingOccurrences(of: "d", with: "s").replacingOccurrences(of: "s", with: "a") .replacingOccurrences(of: "a", with: "p").replacingOccurrences(of: "p", with: "o") .replacingOccurrences(of: "o", with: "i").replacingOccurrences(of: "i", with: "u") .replacingOccurrences(of: "u", with: "y").replacingOccurrences(of: "y", with: "t") .replacingOccurrences(of: "t", with: "r").replacingOccurrences(of: "r", with: "e") .replacingOccurrences(of: "e", with: "w").replacingOccurrences(of: "w", with: "q") .replacingOccurrences(of: "q", with: "m")
print(str)
print(replaced)
var replaced = str.replacingOccurrences(of: "m", with: "n"); print(replaced); replaced = replaced.replacingOccurrences(of: "n", with: "b"); print(replaced"; replaced = ...and debug. You might be able to see what's happening.