Ios 如何对枚举使用NSCoding协议?
我有这个枚举:Ios 如何对枚举使用NSCoding协议?,ios,objective-c,enums,nscoding,Ios,Objective C,Enums,Nscoding,我有这个枚举: typedef types { HBIntineraryTypeVisited = 0, HBIntineraryTypeUnvisited, HBIntineraryTypeUnknown, HBIntineraryTypeDeleted, } HBIntineraryType; 并希望使用nscoding协议将其与其他一些变量一起存储 - (id)initWithCoder:(NSCoder *)aDecoder { self = [
typedef types {
HBIntineraryTypeVisited = 0,
HBIntineraryTypeUnvisited,
HBIntineraryTypeUnknown,
HBIntineraryTypeDeleted,
} HBIntineraryType;
并希望使用nscoding协议将其与其他一些变量一起存储
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
_name = [aDecoder decodeObjectForKey:@"name"];
// todo decode enum object
}
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_name forKey:@"name"];
// todo encode enum object
}
我使用什么编码器方法来解码和编码这种枚举?一般来说,
enum
s的表示形式可能会有所不同。使用Objective-C时,应使用以确保使用哪种类型来表示枚举。有更多的背景。decodeInt
/encodeInt
(带有一些强制转换)。这是将链接作为答案的缺点。你永远不知道他们什么时候会开始显示404:(来自Big Nerd Ranch的大多数博客文章都被移动了。以下是新的url: