Trying to encode string added with special characters with below code:
let encodedString = myString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
which does not include all special characters.
Also tried below options:
- .urlHostAllowed
- .urlFragmentAllowed
- .urlPasswordAllowed
- .urlPathAllowed
- .urlUserAllowed
- .urlQueryAllowed
but it's not working.
Please tell me if there is any other approach for URL encoding to include all special characters.
Edit
Adding : as input in string it converts to %3A. Same way for @ - %40.
But adding & remains same. Required output is %26.