Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
There appears to be some distrust in the iOS SDK, specifically the NSString class method that escapes strings.

Using the following resource as guidance I have created a category class that is an extension of NSString.

http://madebymany.com/blog/url-encoding-an-nsstring-on-ios

.h
Code:
#import <Foundation/Foundation.h>

@interface NSString (URLEncoding)
-(NSString*)urlEncodingUsingEncoding:(NSStringEncoding)encoding;
@end

.m
Code:
@implementation NSString (URLEncoding)
-(NSString*)urlEncodingUsingEncoding:(NSStringEncoding)encoding
{
    return (__bridge NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)self, NULL, (CFStringRef)@"!*'\"();;@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding));
}
@end

When I import this class and attempt to create an instance, I cannot call the class method 'alloc'. Why hasn't this been inherited?

Further, I have tried abandoning the use of this category class and simply calling some C functions as so:

Code:
NSString *escapedString = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)grade,	 NULL,	 (CFStringRef)@"!’\"();:@&=+$,/?%#[]% ", kCFStringEncodingISOLatin1);

However, I'm getting issues with this also. The NSLog that follows this piece of code has a warning from Xcode (slightly above it actually in the empty space between) 'data argument not used by format string':

NSLog(@"Test", escapedString);

Such a simple task, yet so many errors. What am I doing wrong here?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.