目标C:如何继承加载在父类中的类别方法? [英] Objective C: how to inherit category methods loaded in a parent class?

查看:80
本文介绍了目标C:如何继承加载在父类中的类别方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我正在使用NSObject+Properties.h类别(请参阅aqtoolkit: https://github.com/AlanQuatermain/aqtoolkit/blob/master/Extensions/NSObject%2BProperties.h )

In my project, I am using the NSObject+Properties.h category (see aqtoolkit: https://github.com/AlanQuatermain/aqtoolkit/blob/master/Extensions/NSObject%2BProperties.h)

然后有一个我声明为

#import <Foundation/Foundation.h>
#import "NSObject+Properties.h"

@interface GFDictionaryInitiable : NSObject
...

然后我有几个GFDictionaryInitiable的子类,例如GFRestaurant:

I then have several subclasses of GFDictionaryInitiable, such as GFRestaurant:

#import <Foundation/Foundation.h>

#import "GFDictionaryInitiable.h"

@interface GFRestaurant : GFDictionaryInitiable
...

我的问题是我无法访问子类的NSObject+Properties类别中定义的方法.例如,我得到了错误:

My problem is that I cannot access methods defined in the NSObject+Properties category in my subclasses. For example I get the error:

-[GFRestaurant hasPropertyNamed:]: unrecognized selector sent to instance 0x2e57240

如何让我的所有子类继承"父类中加载的类别的方法?

How can I have all my subclasses 'inherit' the category's methods that are loaded in the parent class?

推荐答案

当您获得运行时异常(而不是编译器错误)时,我认为您忘记了 将"NSObject + Properties.m"添加到目标.选择文件并检查 文件检查器中的目标成员身份"复选框.

As you get a runtime exception, and not a compiler error, I assume that you forgot to add "NSObject+Properties.m" to your target. Select the file and check the "Target Membership" checkbox in the File inspector.

这篇关于目标C:如何继承加载在父类中的类别方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆