ローカルストレージ-アーカイブ

1477 ワード

 
#define DCAccountFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.data"]

'DCAccountFilePath '

1.' 
+ (BOOL)archiveRootObject:(id)rootObject toFile:(NSString *)path;
// 
 [NSKeyedArchiver archiveRootObject:account toFile:DCAccountFilePath];
2.' 
+ (nullable id)unarchiveObjectWithFile:(NSString *)path;
// 
DCAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:DCAccountFilePath];

3.' NSCoding , 
@interface DCEmotion : NSObject

- (void)encodeWithCoder:(NSCoder *)aCoder;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;

// 
-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeObject:self.expires_in forKey:@"expires_in"];
    [aCoder encodeObject:self.expires_end forKey:@"expires_end"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
}
// 
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];
    if(self)
    {
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.expires_in = [aDecoder decodeObjectForKey:@"expires_in"];
        self.expires_end = [aDecoder decodeObjectForKey:@"expires_end"];
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
    }
    return self;
}