I am making encoding to my NSString value entered in textfield in iOS app.
This is my code
NSString *encodedStrr = [myTextFeild.text encodeString:NSUTF8StringEncoding];
NSString *encodedUrlStrr = [NSString stringWithFormat:
@"http://www.damain.com:8080/app/f/query?from=%@",
encodedStrr];
NSURL *urlr11 = [NSURL URLWithString: encodedUrlStrr];
I am getting the following error,
2016-04-19 11:45:46.186 FactualNote[3137:11303] -[__NSCFString encodeString:]: unrecognized selector sent to instance 0x71c5100
2016-04-19 11:45:46.187 FactualNote[3137:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [__NSCFString encodeString:]: unrecognized selector sent to instance 0x71c5100'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x30ff 0x10e4705 0x182c0 0x18258 0xd9021 0xd957f 0xd86e8 0x47cef 0x47f02 0x25d4a 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x1eed 0x1e15)
libc++abi.dylib: terminate called throwing an exception
I followed this url to encode https://madebymany.com/blog/url-encoding-an-nsstring-on-ios .
This is the file I am using and import it in viewController.m.
Desing.h
@interface NSString (encode)
- (NSString *)encodeString:(NSStringEncoding)encoding;
@end
Desing.m
@implementation NSString (encode)
- (NSString *)encodeString:(NSStringEncoding)encoding
{
return (NSString *) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self,
NULL, (CFStringRef)@";/?:@&=$+{}<>,",
CFStringConvertNSStringEncodingToEncoding(encoding)));
}
@end
Following post answer says, this could be memory problem Unrecognized Selector Sent to Instance [NSCFString subarrayWithRange:] .
How do I come out from this.
检查您的类别(Desing.m)是否添加到目标中,这可能是原因。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.