How the F*** to Encode URL in Objective-C for IOS

Google it.

You’ll find there are a ton of solutions, all of them produce memory related errors because of ARC.

if you want to do it in a way that works, just:

NSString *charactersToEscape = @"!*'();:@&=+$,/?%#[]" ";
    NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
    NSString *url = [NSString stringWithFormat:@"%@", @""];
    NSString *encodedUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];

Jesus…this took me way too long to figure out

Leave a Reply

Your email address will not be published. Required fields are marked *