清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
-(id)initWithDic:(NSDictionary*)dic { self=[super init]; if (self) { /** *第一步,从字典中取得数组所有的key值 */ NSArray* allKey=[dic allKeys]; for (NSString* key in allKey) { /** *第二步,将传进来的key分割,第一个key的首字母大写,其余小写 */ NSString* firstWord=[[key substringToIndex:1] uppercaseString]; NSString* otherWord=[key substringFromIndex:1]; NSString* setterStr=nil; /** *第三步,判断该key是否是oc的关键字id,是的话,转换成set+类名+key的形式 */ if ([key isEqualToString:@"id"]) { setterStr=[NSString stringWithFormat:@"set%@%@%@:",NSStringFromClass([self class]),firstWord,otherWord]; } else { setterStr = [NSString stringWithFormat:@"set%@%@:", firstWord, otherWord]; } /** *第四步 动态加载实例方法 */ SEL method=NSSelectorFromString(setterStr); NSString* value=dic[key]; if ([self respondsToSelector:method]) { [self performSelector:method withObject:value afterDelay:0.0f]; } } } return self; }