Objective-C:我应该在哪里以及如何声明枚举?
美好的一天,朋友们。 我是 Objective-C 的新手。我想在我的班级中使用枚举并将其公开。 我已经了解如何声明枚举(http://stackoverflow.com/questions/1662183/using-enum-in-objective-c),但我不明白应该在哪里声明它们。
我尝试过:
@interface MyFirstClass : NSObject {
typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}
或:
@interface MyFirstClass : NSObject {
@public
typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}
但编译器抛出错误:“typedef 之前预期有说明符限定符列表”。
怎么了?
Good day, friends.
I'm newbie in Objective-C. I'm wanting to use enum in my class and make it public.
I've understand how to declare enums (http://stackoverflow.com/questions/1662183/using-enum-in-objective-c), but I don't understand where should I declare them.
I've tried:
@interface MyFirstClass : NSObject {
typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}
or:
@interface MyFirstClass : NSObject {
@public
typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}
But compiler throws error: "expected specifier-qualifier-list before typedef".
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.h
.m 文件
.h
.m file
在
@interface
声明之外。Outside of the
@interface
declaration.您可以创建一个头文件 (*.h) 并执行以下操作来匹配您的枚举变量。
用途:
You can create a header file (*.h) and do following to match your enum variable.
Uses: