user1695758
user1695758

Reputation: 173

NSData Unrecognized selector sent to class

I'm getting the following error when running my app:

+[NSData dataFromBase64String:]: unrecognized selector sent to class 0x1aff66598 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSData dataFromBase64String:]: unrecognized selector sent to class 0x1aff66598'

The caller looks like this:

NSString* decodedData = [self base64Decode:encodedData];

And the method definitions are as follows:

- (NSString *)base64Decode:(NSString *)base64String {
    NSData *plainTextData = [NSData dataFromBase64String:base64String];
    NSString *plainText = [[NSString alloc] initWithData:plainTextData encoding:NSUTF8StringEncoding];
    return plainText;
}

// This is in another class
+ (NSData *)dataFromBase64String:(NSString *)aString {
    NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
    if( data == nil )
        return nil;
    size_t outputLength;
    void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
    NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
    free(outputBuffer);
    return result;
}

I'm not sure what I'm doing wrong...

Upvotes: 0

Views: 1534

Answers (1)

Nicolas Buquet
Nicolas Buquet

Reputation: 3955

Is your implementation of 'dataFromBase64String:' in objective-C Category in a static framework or library?

If it is the case, methods in the category are not included at linking and so are not found at runtime unless you add flags '-ObjC -all_load' on OTHER_LINKER_FLAGS in Xcode.

see https://developer.apple.com/library/content/qa/qa1490/_index.html

Upvotes: 3

Related Questions