objective-c - Set up interface definitions for a category, if methods of the category are called from another class
问题描述
Let’s say I have a class Alpha , and a category Alpha+morefeatures with a method -(void)foo. Another class , say Beta, should call the method foo.
I like to use the categories for splitting the code into parts, so that Alpha.m will not be a big file.Where should I put the includes & interface description then?
I tried:
file Alpha.h——————————</p>
@interface Alpha {
...
}
-(void) foo;
file Alpha.m——————————</p>
#import „Alpha.h“
file Alpha+morefeatures.h --------------
#import "Beta.h"
@interface Alpha (morefeatures)
file Alpha+morefeatures.m --------------
#import Alpha+morefeatures.h
@implementation Alpha (morefeatures)
-(void)foo {
...
}
file Beta.h——————————-
#import „Alpha.h“
Alpha+morefeatures.h is not imported anywhere else than in Alpha+morefeatures.m . This compiles ( and runs well) but it gives the following compiler warnings:
“Category is implementing a method which will also be implemented by its primary class”</p>
"Method definition not found"
How can I get rid of the warnings ? I have seen some answers which deal with compiler options - but I assume it is more a syntax problem.
Any advise is appreciated.
解决方案
我终于找到了一个办法:我所要做的就是将接口描述添加到Alpha.h中
@interface Alpha (morefeatures)
-(void)foo;
@end
然后在 Beta.h 中导入Alpha.h
推荐阅读
- tabulator - 列显示为行
- python - 如何调整 DataFrame 中的数据,使其匹配正确的索引日期?
- python-3.x - Binance API期货调整杠杆
- python - 无法安装 keyrings.google-artifactregistry-auth,需要 Rust?
- vb.net - 在下面的代码片段中使用列表时,AddressOf 运算符如何在 VB.net 中工作
- java - java.lang.NoClassDefFoundError: ch/qos/logback/classic/filter/ThresholdFilter
- reactjs - 使用 React 钩子来遵循 DRY 是一种好习惯吗?
- vue.js - 在 Storybook Vue 中导入节点模块
- javascript - React-Redux 操作未生效
- flutter - Android Studio 没有在项目窗格的“Android View”中加载我的 Flutter 项目