Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你如何使用 NSCoder 对自定义类型进行编码和解码?
例如,您将如何将 NSCoder 与“ STATE”实例一起使用,其中:
STATE
typedef enum { ON, OFF } STATE;
您可以将它们视为整数,因为它们是隐式分配的整数值:
- (void) encodeWithCoder: (NSCoder *)coder { ... [coder encodeInt:type forKey:@"state"]; } - (id) initWithCoder: (NSCoder *)coder { ... state = [coder decodeIntForKey:@"state"]; }