@interface JAXOneShipCompany : NSObject <NSCoding>
@property (nonatomic, strong, readonly) NSString *ID;
@property (nonatomic, strong, readonly) NSString *NameCN;
@property (nonatomic, strong, readonly) NSString *NameEN;
@property (nonatomic, assign, readonly) NSInteger OrderIndex;
@property (nonatomic, strong, readonly) NSString *Remark;
@property (nonatomic, strong, readonly) NSString *SCAC;
@end
@implementation JAXOneShipCompany
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
_ID = [aDecoder decodeObjectForKey:@"ID"];
_NameCN = [aDecoder decodeObjectForKey:@"NameCN"];
_NameEN = [aDecoder decodeObjectForKey:@"NameEN"];
_OrderIndex = [[aDecoder decodeObjectForKey:@"OrderIndex"] integerValue];
_Remark = [aDecoder decodeObjectForKey:@"Remark"];
_SCAC = [aDecoder decodeObjectForKey:@"SCAC"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:_ID forKey:@"ID"];
[aCoder encodeObject:_NameCN forKey:@"NameCN"];
[aCoder encodeObject:_NameEN forKey:@"NameEN"];
[aCoder encodeObject:@(_OrderIndex) forKey:@"OrderIndex"];
[aCoder encodeObject:_Remark forKey:@"Remark"];
[aCoder encodeObject:_SCAC forKey:@"SCAC"];
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, %@>",
[self class],
self,
@{
@"ID" : _ID,
@"NameCN" : _NameCN,
@"NameEN" : _NameEN,
@"OrderIndex" : @(_OrderIndex),
@"Remark" : _Remark,
@"SCAC" : _SCAC
}
];
}
@end
归档
static NSString *const kHistoryFscPath = @"JAX_kHistoryFscPath.txt";
- (NSString *)private_kHistoryFscPath {
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent: kHistoryFscPath];
}
if (![NSKeyedArchiver archiveRootObject:self.historyFsc toFile:[self private_kHistoryFscPath]]) {
NSLog(@"NSKeyedArchiver Error!");
}
解档
self.historyFsc = [NSKeyedUnarchiver unarchiveObjectWithFile:[self private_kHistoryFscPath]];