我在实现文件中声明了一个枚举,如下所示,并在接口中声明了该类型的变量作为 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
};
记录在这里 https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)