关于这一点的任何经验,例如,我有以下用objc编写的枚举
typedef enum {
Type1,
Type2
} Type;
extension Type: RawRepresentable {
typealias RawValue = UInt32
}当我试图遵循RawRepresentable.The时,编译器崩溃了,我唯一能想象的就是RawRepresentable只适用于swift枚举。
有什么想法吗?
发布于 2019-12-02 21:03:39
忘记使用原始C枚举,使用Objective-C NS_ENUM宏:
typedef NS_ENUM(NSInteger, MyEnumType) {
Type1,
Type2
};那么在Swift中枚举就已经是RawRepresentable了。您不能以这种方式添加该一致性。嗯,你也许可以,但是你还必须声明init?(rawValue:)和var rawValue。
https://stackoverflow.com/questions/59139314
复制相似问题