Skip to content

Instantly share code, notes, and snippets.

@jschmid
Created July 23, 2014 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jschmid/5368a49c50f08f45895f to your computer and use it in GitHub Desktop.
Save jschmid/5368a49c50f08f45895f to your computer and use it in GitHub Desktop.
Objective-C URL encoding
+ (NSString *)encodedString:(NSString *)unescaped {
NSString *charactersToEscape = @"!*'();:@&=+$,/?%#[]\" ";
NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
NSString *encodedString = [unescaped stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
return encodedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment