美文网首页
归档解档

归档解档

作者: 写代码写到人生巅峰 | 来源:发表于2017-05-11 17:43 被阅读0次
    @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]];

    相关文章

      网友评论

          本文标题:归档解档

          本文链接:https://www.haomeiwen.com/subject/mltatxtx.html