String replacement in Swift looks trivial—until you touch emojis, flags, or anything outside the Unicode BMP. Then subtle Unicode details start leaking through the NSString class. Here’s a concrete example that exposes the problem.
1. The Surprising Result
let result = "🇨🇦🇺🇸".replacingOccurrences(of: "🇦🇺", with: "🇳🇮")Result:
🇨🇳🇮🇸At first glance…


