我在我的实现文件中声明了一个枚举,如下所示,并在我的接口(interface)中声明了一个该类型的变量作为 PlayerState thePlayerState;并在我的方法中使用了该变量。但我收到错误,指出它未声明。如何在我的方法中正确声明和使用 PlayerState 类型的变量?:
在.m文件中
@implementation View1Controller
typedef enum playerStateTypes
{
PLAYER_OFF,
PLAYER_PLAYING,
PLAYER_PAUSED
} PlayerState;
在 .h 文件中:
@interface View1Controller : UIViewController {
PlayerState thePlayerState;
在 .m 文件中的某些方法中:
-(void)doSomethin{
thePlayerState = PLAYER_OFF;
}
最佳答案
Apple 提供了一个宏来帮助提供更好的代码兼容性,包括 Swift。使用宏如下所示。
typedef NS_ENUM(NSInteger, PlayerStateType) {
PlayerStateOff,
PlayerStatePlaying,
PlayerStatePaused
};
Documented here
https://stackoverflow.com/questions/2212080/