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
.m
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:
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?
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?