NSCoder and Custom Types

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

For example, how do you use NSCoder with an instance of " STATE ", where:

 typedef enum { ON, OFF } STATE; 
+7
types nscoder
source share
1 answer

You can consider them as integers, since they are implicitly assigned by integer values:

 - (void) encodeWithCoder: (NSCoder *)coder { ... [coder encodeInt:type forKey:@"state"]; } - (id) initWithCoder: (NSCoder *)coder { ... state = [coder decodeIntForKey:@"state"]; } 
+13
source share

All Articles