之前遇到幾十個(gè)屬性的模型庆亡,簡(jiǎn)直寫到惡心夜焦,所以找了這么個(gè)方法偷懶
這個(gè)方法需要不斷完善,畢竟里面的類型我只寫了幾個(gè)罩息,到時(shí)候控制臺(tái)就會(huì)完整打印出來(lái)
+ (void)createPropertyCodeWithDic:(NSDictionary *)dic{
NSMutableString *string = [NSMutableString string];
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull propertyName, id _Nonnull value, BOOL * _Nonnull stop) {
NSLog(@"---%@ %@",propertyName,[value class]);
NSString *code;
if ([value isKindOfClass:NSClassFromString(@"__NSCFString")]) {
code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSString *%@;",propertyName];
}else if([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
code = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",propertyName];
}else if([value isKindOfClass:NSClassFromString(@"__NSCFArray")]){
code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName];
}else if([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName];
}else if([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName];
}
[string appendFormat:@"\n%@\n",code];
}];
NSLog(@"%@",string);
}