开发者

NSCoder and custom types

How do you use NSCoder to encode and decode custom types?

For example, how would you use NSCoder with 开发者_如何学编程an instance of "STATE" where:

typedef enum { ON, OFF } STATE;


You can treat them as integers as they are implicitly assigned integer values:

- (void) encodeWithCoder: (NSCoder *)coder {
  ...
  [coder encodeInt:type forKey:@"state"];
}

- (id) initWithCoder: (NSCoder *)coder {
  ...
  state = [coder decodeIntForKey:@"state"];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜