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
#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
相关文章推荐
- IOS8 addressbook获取全部联系人
- IOS 利用桥接整合通讯录读取全部联系人
- IOS8 通讯录修改添加联系人
- IOS Block随笔
- 【iOS】一不小心破解了别人的静态库
- iOS下编译FFmpeg库
- 玩转iOS开发 - 数据缓存
- iOS项目开发小技巧 (四) --实现类似弹出窗口(View)
- iOS开发-Certificates、Identifiers和Profiles详解
- IOS基础 总结
- 自己动手解Json!(IOS利用分治法解析Json)(一)
- debian的ios下载及源设置
- IOS常用正则表达式
- NSUserDefaults
- ios aes加密
- iOS设计模式——Category和 Extension
- ios des加密
- ios data转换成16进制字符串以及16进制字符串转data
- iOS中CG绘图笔记
- iOS app 崩溃日志符号化及代码定位