AnnounceModel.m 934 Bytes
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//
//  AnnounceModel.m
//  redstar
//
//  Created by admin on 15/11/30.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "AnnounceModel.h"

@implementation AnnounceModel
+ (instancetype)announceModelWithDict:(NSDictionary *)dict
{
    return [[self alloc] initWithDict:dict];
}

- (instancetype)initWithDict:(NSDictionary *)dict
{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}
admin's avatar
admin committed
24 25 26 27 28 29 30 31 32 33 34
- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues{
    Class cls = self.class;
    for (NSString *key in keyedValues.allKeys) {
        NSString *varName = [NSString stringWithFormat:@"_%@", key];
        const char *c_key = [varName cStringUsingEncoding:NSUTF8StringEncoding];
        Ivar var = class_getInstanceVariable(cls, c_key);
        if (var) {
            [self setValue:[keyedValues objectForKey:key] forKey:key];
        }
    }
}
admin's avatar
admin committed
35
@end