我正在开发一个应用程序,当我尝试使用NSCoding
对具有枚举属性的模型进行编码时,遇到了问题。因此,我想将其转换为rawValue
,再进行反向操作。我搜索了一下,找到了宏NS_ENUM
,所以我的代码看起来像这样:
typedef NS_ENUM(NSInteger, SectionType) {
SectionTypeText = 0,
SectionTypeVideo = 1,
SectionTypeLink = 2,
SectionTypeFile = 3,
SectionTypeQuiz = 4,
SectionTypeAudio = 5,
SectionTypeGame = 6,
SectionTypeHomework = 7
};
但是我找不到任何可能的方法将它们转换为相关值,然后再进行反向操作。怎么办?有比NS_ENUM宏更好的方法吗?
NSCoding
有关,只需将其视为NSInteger
属性进行编码/解码处理即可。 - LarmeSectionType s = 5;
,然后判断s == SectionTypeAudio
等等... - Grady Player