Question

I'm trying to Decode URL,but i'm getting warning message like "NSString may not respond to URLDecode".

NSString* token = [[urlStr substringFromIndex:r.location + 1] URLDecode];

Any ideas?

Was it helpful?

Solution

Because it is not a method a classic NSString respond to, you can though add a category like the following, to add the method yourself :

@interface NSString (URLDecode)
- (NSString *)URLDecode;
@end

@implementation NSString
- (NSString *)URLDecode
{
    NSString *result = [(NSString *)self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
    result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return result;
}
@end

OTHER TIPS

Try like this.

NSString* urlEncoded = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

and check this link https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/TP40003744

it may help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top