【发布时间】:2011-06-02 12:26:07
【问题描述】:
请参考以下代码:
文件名:myclass.h
@interface myclass:NSObject
...
@end
@interface NSObject(CategoryName)
....
@end
我不明白我们如何在同一个 .h 文件中声明 2 个 @interface 指令?和在实现文件中一样,我们只能实现上述接口之一。例如。
文件名:myclass.m
@implementation myclass
...
@end
在上面的代码中,我不能写@implementation Categoryname,因为 .h 文件的名称是 myclass。我如何实现类别中描述的方法。
我的主界面也可以扩展一个类,而我在同一个 .h 文件中定义的类别可以扩展另一个类吗?
如何在目标 c 中将一个类声明为另一个类(嵌套类)?
提前谢谢你。
更新
阅读回复后,我还有 2 个问题
- 如果我的 .h 文件中有 2 个@interface,我可以在 .m 文件中有 2 个 @implementation。
- 如果我的 .h 文件中有 2 个 @interface,并且如果我将该 .h 文件导入另一个文件中,我可以访问这两个 @interface 指令下的方法吗?
- 我可以在另一个类的接口中实现类别中声明的方法吗?
【问题讨论】:
标签: objective-c