objective-c - 错误: unrecognized selector sent to class

标签 objective-c class interface

对于 Objective C(甚至对于 OOP 而言),我完全是个菜鸟。这就是我正在尝试做的事情

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 
}

当我运行此命令时,我收到一条错误消息,提示失败:

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

最佳答案

尽管您在 @interface 部分声明了 +inst 方法,但您的类并未实现它,这会导致运行时错误。您需要添加实现才能使其工作,例如

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

关于objective-c - 错误: unrecognized selector sent to class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35278798/

相关文章:

html - spring 形式的 class 和 cssClass 属性有什么区别

java - 如何声明包含实现接口(interface)的类的子类的变量?

C# 类型需要特定类的子类以及接口(interface)

ios - 创建 UIImage 数组

ios - FBSDKCoreKit.framework/FBSDKCoreKit : no matching architecture in universal wrapper

ios - 如何向 XCode 中的方法填充助手添加信息?

python - 每次在 python 中调用时都会更新 __init__ 中的 self 变量

javascript - 在coffeescript中定义类, 'Cannot read property ' apply' of undefined'

c# - 无法解释错误消息 'async is not valid for this item'

ios - UITableViewAutomaticDimension 不工作