ios 根据字典自动生成属性

 

- (void)createPropertyCode
{
NSMutableString *codes = [NSMutableString string];
// 遍历字典
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) {
NSString *code;
if ([value isKindOfClass:[NSString class]]) {

code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@",key];

}else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){

code = [NSString stringWithFormat:@"@property (nonatomic, assion) BOOL %@",key];

}else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){

code = [NSString stringWithFormat:@"@property (nonatomic, assion) NSInteger %@",key];

}else if ([value isKindOfClass:NSClassFromString(@"__NSArrayI")]){

code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@",key];

}else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){

code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@",key];

}

[codes appendFormat:@"\n%@\n",code];

}];
NSLog(@"codes = %@",codes);
}

posted @ 2019-03-20 21:19  SoulDu  阅读(148)  评论(0编辑  收藏  举报