ExceptionHandler
ExceptionHandler

Reputation: 223

Error : unrecognized selector sent to class

I am a complete noob when it comes to Objective C (or even for OOP for that matter). Here is what I am trying to do

AInterface.m

@implementation AInterface

 - (BOOL)getParam:(NSData **)a param1:(NSData**)param1 param2:(NSData**)param2
{

       //Do a bunch of things
       return bool;
} 

@end

AInterface.h

@interface AInterface : NSObject

- (BOOL)getParam:(NSData **)a param1:(NSData**)param1 param2:(NSData**)param2;

+ (instancetype) inst;
@end

testMain.m()

int main()
{
    Bool result = NO;
    NSData *a = Nil;
    NSData *b = Nil;
    NSData *c = Nil;

    result = [[AInterface inst] getParam:(NSData **)&a param1:(NSData**)&a param2:(NSData**)&b];

    return result 
}

When I run this though, I get an error saying failed:

 caught "NSInvalidArgumentException", "+[AInterface inst]: unrecognized selector sent to class 

Upvotes: 2

Views: 1581

Answers (2)

Jacob Gorban
Jacob Gorban

Reputation: 1461

Your problem is that you don't have implementation of +inst in AInterface.m. In your case inst would be something like: [[AInterface alloc] init] but I'd just use [[AInterface alloc] init] instead of calling inst in the first place. Or [AInterface new], which stands for the same.

In general, the rest of your code is not idiomatic Objective-C.

Upvotes: 1

Vladimir
Vladimir

Reputation: 170849

Although you declared +inst method in @interface section your class does not have it implemented and that leads to runtime error. You need to add implementation to make it work, e.g.

@implementation AInterface
...
+ (instancetype)inst {
   return [self new];
}

Upvotes: 4

Related Questions