Posts Tagged NSUrl

iPhone tip #1 – URL encoding in Objective-C

If you are n00b when it comes to iPhone development, then you’ve come to the right place! We’ll be posting howtos, tips and tricks continuously.

So, how do you URL enconde a string? It’s quite simple if you know how. :)

+ (NSString *)urlEncodeValue:(NSString *)str
{
NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)str, NULL, CFSTR(:/?#[]@!$&’()*+,;=”), kCFStringEncodingUTF8);
return [result autorelease];
}

To create an URL object, do like this:

[NSURL URLWithString:encodedUrlString]

, , , , , , ,

10 Comments