您的位置:首页 > 移动开发 > IOS开发

IOS8文件归档NSKeyedArchive的使用方法

2015-06-10 00:00 357 查看
摘要: NSKeyedArchive的使用方法

#import <Foundation/Foundation.h>

@interface SJAccount : NSObject

@property (nonatomic,copy) NSString *access_token;

@property (nonatomic,assign) long long expires_in;

@property (nonatomic,assign) long long remind_in;

@property (nonatomic,assign) long long uid;

- (instancetype)initWithDict:(NSDictionary *)dict;

+ (instancetype)accountWithDict:(NSDictionary *)dict;

@end

#import "SJAccount.h"

@interface SJAccount () <NSCoding>

@end

@implementation SJAccount

- (id)initWithCoder:(NSCoder *)aDecoder

{

if (self = [super init]) {

self.access_token = [aDecoder decodeObjectForKey:@"access_token"];

self.remind_in = [aDecoder decodeInt64ForKey:@"remind_in"];

self.expires_in = [aDecoder decodeInt64ForKey:@"expires_in"];

self.uid = [aDecoder decodeInt64ForKey:@"uid"];

}

return self;

}

- (void)encodeWithCoder:(NSCoder *)aCoder

{

[aCoder encodeObject:self.access_token forKey:@"access_token"];

[aCoder encodeInt64:self.remind_in forKey:@"remind_in"];

[aCoder encodeInt64:self.expires_in forKey:@"expires_in"];

[aCoder encodeInt64:self.uid forKey:@"uid"];

}

- (instancetype)initWithDict:(NSDictionary *)dict

{

if (self = [super init]) {

[self setValuesForKeysWithDictionary:dict];

}

return self;

}

+ (instancetype)accountWithDict:(NSDictionary *)dict

{

return [[self alloc] initWithDict:dict];

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: