// // MyModel.m // DSH // // Created by 张毅成 on 2018/9/26. // Copyright © 2018 WZX. All rights reserved. // #import "MyModel.h" @implementation MyModel + (NSDictionary *)modelCustomPropertyMapper { return @{@"headimgurl" : @"userLogo", @"wxHeadImgUrl" : @"headimgurl" }; } - (NSMutableArray *)arrayData { if (!_arrayData) { _arrayData = @[ @[@""], @[ @{@"title": @"同行阅读动态", @"titleImage": @"005", @"detail": @""}, @{@"title": @"学习报告", @"titleImage": @"009", @"detail": @""}], @[ @{@"title": @"作者认证", @"titleImage": @"006", @"detail": @""}, @{@"title": @"我的论文", @"titleImage": @"004", @"detail": @""}, @{@"title": @"账户", @"titleImage": @"007", @"detail": @""}], @[ @{@"title": @"我的会员", @"titleImage": @"001", @"detail": @""}, @{@"title": @"分享", @"titleImage": @"分享", @"detail": @""}], @[ @{@"title": @"设置", @"titleImage": @"003", @"detail": @""}]].mutableCopy; } return _arrayData; } - (NSMutableArray *)achievementList { if (!_achievementList) { _achievementList = @[].mutableCopy; } return _achievementList; } /* 使用runtime进行解档与归档。 */ - (void)encodeWithCoder:(NSCoder *)aCoder { unsigned int count = 0; Ivar *ivarLists = class_copyIvarList([MyModel class], &count);// 注意下面分析 for (int i = 0; i < count; i++) { const char* name = ivar_getName(ivarLists[i]); NSString* strName = [NSString stringWithUTF8String:name]; [aCoder encodeObject:[self valueForKey:strName] forKey:strName]; } free(ivarLists); //一定不要忘了,自己释放。 } - (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super init]) { unsigned int count = 0; Ivar *ivarLists = class_copyIvarList([MyModel class], &count); for (int i = 0; i < count; i++) { const char* name = ivar_getName(ivarLists[i]); NSString* strName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding]; id value = [aDecoder decodeObjectForKey:strName]; [self setValue:value forKey:strName]; } free(ivarLists); } return self; } @end