一个 JSON 转 Model 属性代码的 Mac 小工具,目前支持 Objective-C,Swift class, Swift struct 。
switch (obj.propertyType) {
case BMPropertyTypeInt:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ = 0" ,
obj.propertyName]];
break ;
case BMPropertyTypeBoolean:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ = false" ,
obj.propertyName]];
break ;
case BMPropertyTypeString:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ = \"\" " ,
obj.propertyName]];
break ;
case BMPropertyTypeArray:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ : Array<<#type#>> = []" ,
obj.propertyName]];
break ;
case BMPropertyTypeDictionary:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ : <#type#>?" ,
obj.propertyName]];
break ;
case BMPropertyTypeObject:
[propertyArray addObject: [NSString stringWithFormat: @" var %@ : <#type#>?" ,
obj.propertyName]];
break ;
default :
break ;
}
支持 Objective-C 只需如下代码即可:
switch (obj.propertyType) {
case BMPropertyTypeInt:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, assign) NSInteger %@ ;" ,
obj.propertyName]];
break ;
case BMPropertyTypeBoolean:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, assign) BOOL %@ ;" ,
obj.propertyName]];
break ;
case BMPropertyTypeString:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, copy) NSString *%@ ;" ,
obj.propertyName]];
break ;
case BMPropertyTypeArray:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, copy) NSArray <<#type#> *> *%@ ;" ,
obj.propertyName]];
break ;
case BMPropertyTypeDictionary:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, strong) <#type#> *%@ ;" ,
obj.propertyName]];
break ;
case BMPropertyTypeObject:
[propertyArray addObject: [NSString stringWithFormat: @" @property (nonatomic, strong) <#type#> *%@ ;" ,
obj.propertyName]];
break ;
default :
break ;
}