I am trying to url encode a string in my iOS 5 app using ARC.
This is how i do it:
- (NSString *)escape:(NSString *)text
{
return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(__bridge CFStringRef)text, NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
}
I then call it with test data like this:
NSLog([self escape:@"kalel///&&&???"]);
But the output i get from the NSLog
is this:
kalel0.0000000.0000000.00000022623F0.0000000.000000
That just does not seem right, but no matter what I can't get it right
Your
escape
function is fine. The problem is in a way you callNSLog
:escape
produces the stringkalel%2F%2F%2F%26%26%26%3F%3F%3F
for your input.NSLog
interprets this string as a format string and prints some garbage as floating point numbers right afterkalel
word!You should always call
NSLog
with a string constant as a first argument, e.g.:P.S. You have a memory leak in
escape
--- you shouldreturn (__bridge_transfer NSString *)
as you transfer retained CF object to Objective C space.