If you're tired of CFURLCreateStringByAddingPercentEscapes()
, try this.
I didn't write a Swift version, but it should be easy for you to adapt.
It is both funny and ironic that until today, in 2025, the standard library of Apple’s Cocoa ecosystem still lacks out-of-the-box but versatile APIs that can handle these most basic (and important) things "correctly", and vary with different common scenarios.
For test reference: