-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathAccount.m
61 lines (51 loc) · 1.43 KB
/
Account.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Account.m
// CocoaAsyncSocket_TCP
//
// Created by 孟遥 on 2017/4/20.
// Copyright © 2017年 mengyao. All rights reserved.
//
#import "Account.h"
@implementation Account
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
+ (instancetype)account
{
static Account *account = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
account = [[Account alloc]init];
});
return account;
}
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super init]) {
unsigned int count = 0;
Ivar *ivar = class_copyIvarList([Account class], &count);
for (NSInteger index = 0; index<count; index++) {
Ivar iva = ivar[index];
const char *name = ivar_getName(iva);
NSString *strName = [NSString stringWithUTF8String:name];
id value = [decoder decodeObjectForKey:strName];
[self setValue:value forKey:strName];
}
free(ivar);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
unsigned int count;
Ivar *ivar = class_copyIvarList([Account class], &count);
for (NSInteger index = 0; index <count; index++) {
Ivar iv = ivar[index];
const char *name = ivar_getName(iv);
NSString *strName = [NSString stringWithUTF8String:name];
id value = [self valueForKey:strName];
[encoder encodeObject:value forKey:strName];
}
free(ivar);
}
@end