在 Objective-C 这种语法较为繁复的语言中,手动编写属性声明及 YYModel 或 MJExtension 的映射逻辑非常耗时。本工具支持一键将 JSON 数据 转换为结构严谨、符合命名规范的 .h 和 .m 源代码。
.h 文件,省去逐个输入 @property 的过程。本站深度适配了 Objective-C 的语言特性与主流第三方框架:
String -> NSString, Number -> NSInteger/CGFloat, Boolean -> BOOL。NSString, NSArray)自动添加 copy 或 strong。
NSInteger, BOOL)自动添加 assign。+modelCustomPropertyMapper 方法。+mj_replacedKeyFromPropertyName 映射方法。.h 和 .m 文件的联动生成,无需等待。EB, YY),符合 Objective-C 避免类名冲突的最佳实践。snake_case(蛇形)键名转换为 Objective-C 的 camelCase(驼峰)属性名。User) 和 类名前缀 (如 EB)。
原始 JSON:
{
"user_id": 1001,
"user_name": "iOSDev",
"is_vip": true
}
生成的 Objective-C 代码 (YYModel 风格):
EBUser.h
@interface EBUser : NSObject
@property (nonatomic, assign) NSInteger userId;
@property (nonatomic, copy) NSString *userName;
@property (nonatomic, assign) BOOL isVip;
@end
EBUser.m
Objective-C
@implementation EBUser
+ (NSDictionary *)modelCustomPropertyMapper {
return @{@"userId": @"user_id",
@"userName": @"user_name",
@"isVip": @"is_vip"};
}
@end