In iOS8 and prior I can use:
NSString *str = ...; // some URL
NSString *result = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
in iOS9 stringByAddingPercentEscapesUsingEncoding
has been replaced with stringByAddingPercentEncodingWithAllowedCharacters
:
NSString *str = ...; // some URL
NSCharacterSet *set = ???; // where to find set for NSUTF8StringEncoding?
NSString *result = [str stringByAddingPercentEncodingWithAllowedCharacters:set];
and my question is: where to find needed NSCharacterSet
(NSUTF8StringEncoding
) for proper replacement of stringByAddingPercentEscapesUsingEncoding
?
Swift 2.2:
Adding to the accepted answer. Taking into consideration this note
the whole URL should not be encoded: