示例:
我发现枚举UIViewAnimationCurve
太长了。我想写CurveEaseIn
。
所以我试图创建一个别名:
typedef NS_ENUM(NSInteger, CurveEase) {
CurveEaseInOut = UIViewAnimationCurveEaseInOut,
CurveEaseIn = UIViewAnimationCurveEaseIn,
CurveEaseOut = UIViewAnimationCurveEaseOut
};
当我在需要指定UIViewAnimationCurve
的地方使用我的新枚举时,我必须抛出它,否则Xcode会抛出警告:
Implicit conversion from enumeration type 'enum CurveEase' to different enumeration type 'UIViewAnimationCurve' (aka 'enum UIViewAnimationCurve')
我也尝试过:
typedef NS_ENUM(UIViewAnimationCurve, CurveEase) {
CurveEaseInOut = UIViewAnimationCurveEaseInOut,
CurveEaseIn = UIViewAnimationCurveEaseIn,
CurveEaseOut = UIViewAnimationCurveEaseOut
};
注意UIViewAnimationCurve
作为枚举的类型。这给出了错误:
Non-integral type 'UIViewAnimationCurve' (aka 'enum UIViewAnimationCurve') is an invalid underlying type
所以看起来我坚持使用NSInteger作为类型。但有没有办法欺骗编译器接受CurveEase而不进行强制转换,并且没有抑制警告?
答案 0 :(得分:3)
typedef UIAnimationCurve CurveEase
怎么样?