Returns a new string made from the receiver by replacing all characters not in the specified set with percent-encoded characters.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Returns the encoded string, or
nil if the transformation is not possible.
Entire URL strings cannot be percent-encoded, because each URL component specifies a different set of allowed characters. For example, the query component of a URL allows the “
@” character, but that character must be percent-encoded in the password component.
UTF-8 encoding is used to determine the correct percent-encoded characters. Any characters in
allowed outside of the 7-bit ASCII range are ignored.