//NSSecureCoding is the native binary
//serialization of objects
@interface Data : NSObject <NSSecureCoding>
@property (nonatomic) NSString *text;
@property (nonatomic) double num;
@end
@implementation Data
+ (BOOL)supportsSecureCoding {
return YES;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.text
forKey:@"text"];
[coder encodeDouble:self.num
forKey:@"num"];
}
- (instancetype)initWithCoder:
(NSCoder *)coder {
self = [super init];
if (self) {
_text = [coder
decodeObjectOfClass:[NSString class]
forKey:@"text"];
_num = [coder
decodeDoubleForKey:@"num"];
}
return self;
}
@end
Data *data = [Data new];
data.text = @"Hello";
data.num = 3.14;
NSData *bin = [NSKeyedArchiver
archivedDataWithRootObject:data
requiringSecureCoding:YES
error:nil];
//bin.length bytes of binary plist