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"];
}
精彩评论