Created
August 1, 2017 06:40
-
-
Save Wooder/f08a1d40fe345806c36fc0faf36cce1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func urlEncodeString(_ string: String) -> String { | |
#if swift(>=3.0) | |
let allowedCharacterSet = (CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[] ").inverted) | |
if let escapedString = string.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) { | |
return escapedString | |
} | |
#else | |
let allowedCharacterSet = (NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[] ").invertedSet) | |
if let escapedString = string.stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacterSet) { | |
return escapedString | |
} | |
#endif | |
Log.Error.log("Could not urlencode \(string)") | |
return string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment