如果不是,并且需要将其包含在单独的文件中(例如 MyEnums.h),是否每次 .m 或 .h 文件想要引用类型或其中一个值时都需要 #import MyEnums.h?
这是 MyClass.h 的示例代码:
#import <Foundation/Foundation.h>
// #1 placeholder
@interface MyClass : NSObject {
}
// #2 placeholder
- (void)sampleMethod:(MyEnum)useOfEnum;
// #3 placeholder
@end
这是我要定义的枚举:
typedef enum MyEnum {
Value1,
Value2
}
如果我尝试将我的枚举定义放在 #1 中,我会收到错误:在 'interface' 之前可能没有指定类型或存储类。
如果我尝试将枚举定义放在 #2 中,我会收到错误:预期标识符或 '(' before 'end'。
如果我尝试将我的枚举定义放在 #3 中,我会在 'MyEnum' 之前得到 error: expected ')'。这是抱怨参数“useOfEnum”,因为它的类型尚未定义。
那么这可以做到吗?或者什么是最好的方法来做到这一点并限制所需的#imports 数量?