Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Unrecognized Selector to Implementation

I have an ARC project setup in xcode. To that project I added a non-arc static library. Everything works and builds find. When I run the project I get this error.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString encodedURLParameterString]: unrecognized selector sent to instance 0x4a030'

from this code:

NSString * value = [params objectForKey:key];
[_params setObject:[value encodedURLParameterString] forKey:key];

that's trying to call this

@implementation NSString (OAURLEncodingAdditions)

- (NSString *)encodedURLParameterString {
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                           (CFStringRef)self,
                                                                           NULL,
                                                                           CFSTR(":/=,!$&'()*+;[]@#?"),
                                                                           kCFStringEncodingUTF8);
    return [result autorelease];
}

@end

The error seems to be saying that it can't find this function. Of course it compiles just fine and I can jump to the definition just fine. The string value is a constant string which of course inherits from NSString. This works just fine in the other project that I pulled it from. It finds this function perfectly so as an Xcode newbie I'm at my wits end.

The file is included in the compile sources. There aren't any errors and it compiles and runs other code just fine. I seem to be missing one small part and I just can't understand what it is. If you can help please do.

like image 410
Kyle Avatar asked Jul 23 '26 08:07

Kyle


2 Answers

Use the -ObjC and / or -all_load linker flags in your project. Reference: What does the -all_load linker flag do?

like image 131
Carl Veazey Avatar answered Jul 25 '26 07:07

Carl Veazey


// file NSString+URLEncoding.m
#import <Foundation/Foundation.h>
@interface NSString (OAURLEncodingAdditions)
- (NSString *)encodedURLParameterString;
@end

// file NSString+URLEncoding.h - this file is marked with -fno-objc-arc
#import "NSString+URLEncoding.h"
@implementation NSString (OAURLEncodingAdditions)
- (NSString *)encodedURLParameterString {
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                           (CFStringRef)self,
                                                                           NULL,
                                                                           CFSTR(":/=,!$&'()*+;[]@#?"),
                                                                           kCFStringEncodingUTF8);
    return [result autorelease];
}
@end

Given the code above, this code should work:

#import "NSString+URLEncoding.h"
// ...
NSString * value = @"xxxxx";
value = [value encodedURLParameterString];
like image 36
Jano Avatar answered Jul 25 '26 06:07

Jano