ios - NSString URL decode?

ios, objective-c, urldecode

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

Problem

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?

Original source

Related problems