0

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.

Community
  • 1
  • 1
  • Added more details to this, pls take a look –  Apr 19 '16 at 06:22
  • on which text in text filed this crashes or for every text? since code looks fine, may be the problem is with text field – Suhas Arvind Patil Apr 19 '16 at 06:24
  • my textfeild value is 'http://zeptoh.com/lynked/sel.html' about the error, I updated my question with complete error on my console. –  Apr 19 '16 at 06:27
  • 1
    That's not the actual code. The exception complains about **encodeString1** – vadian Apr 19 '16 at 06:35
  • No, Actually I changed it to test it as renamed, It is actually sayd encodeString only. –  Apr 19 '16 at 06:39
  • Is the method called exactly "encodeString" in both the header and the implementation (.m) file? It sounds to me like your header says "encodeString" but your implementation says "encodeString1" or vice versa? – siburb Apr 19 '16 at 07:00

1 Answers1

0

Check if your category (Desing.m) is added to your target, that may be the reason.

Olga Nesterenko
  • 1,324
  • 11
  • 15