Skip to content

Instantly share code, notes, and snippets.

@hashaam
Last active November 13, 2017 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashaam/992a0cecb1749cc0090ed2f22e77a82a to your computer and use it in GitHub Desktop.
Save hashaam/992a0cecb1749cc0090ed2f22e77a82a to your computer and use it in GitHub Desktop.
URL Encode only Unicode Characters
// https://hashaam.com/2017/11/13/url-encode-only-unicode-characters/
let originalURLString = "https://www.exampleserver.com/articles/latest/لن-تصدق-ما-يمكن-أن-تجده-في-مطبخك-فاحذر-غسل-هذه-الأداة.html"
let allowedCharacterSet = CharacterSet.urlFragmentAllowed
let urlString = originalURLString.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)!
let url = URL(string: urlString)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment