Unrecognized selector sent to instance when calling category method

I have a static library that I made to encrypt XML serialization using in my projects. This code has worked fine so far. but when I included it in my last project, I got an error, I know that this error usually occurs when the object I call does not have proper distribution, because this is not the case when NSLog returns NSData for my encryption.

What could be the problem?

The error I get is this

- [NSConcreteData base64EncodingWithLineLength:]: unrecognized selector sent to instance 0x1c9150

* Application termination due to an uncaught exception 'NSInvalidArgumentException', reason: '- [NSConcreteData base64EncodingWithLineLength:]: unrecognized selector sent to instance 0x1c9150

Here is my code:

NSData * encryptedMsg =[crypto encrypt:MsgEnc key:[accessdata->Certificate dataUsingEncoding:NSUTF8StringEncoding] padding:&padding]; NSLog(@"encryptedMsg %@",encryptedMsg); NSString * msg = [NSString stringWithFormat:@"%@", [encryptedMsg base64EncodingWithLineLength:0]]; 
+4
source share
3 answers

As far as I know, base64EncodingWithLineLength is a method that is not defined in NSData , but in a category called NSData+Base64.h . The reason you get the error message is because you did not add this category to your project, so the method is called, it was not found.

Therefore, you must add the "NSData + Base64. *" Files to your project. Get them from here .

EDIT:

Since the OP mentions that the category is included in the static library and it is assumed that the static library is correctly linked, a possible solution to this problem is to add

 -ObjC 

check the "Other linker flags" checkbox in the build settings. This flag will force all characters in the Objective-C category to be loaded, preventing them from being optimized through the linker.

+12
source

I'm afraid base64EncodingWithLineLength: is a category method attached to NSData . This means that you must compile / link to code that implements base64EncodingWithLineLength for the NSData category.

+2
source

This can help if the category belongs to the Core Data object: set the class for the object in the managed object model.

0
source

All Articles