|
5 | 5 |  |
6 | 6 |  |
7 | 7 |
|
8 | | -- 支持Objective-C / Swift / Dart / TypeScript |
9 | | -- 支持通过URL链接或json字符串一键生成model文件 |
10 | | -- 兼容YYModel / MJExtension / HandyJSON解析 |
11 | | -- 支持字符串加密(可设置不同的密钥,开发者可自行修改加密算法) |
12 | | -- 支持自定义model父类名、自定义model前缀、自定义作者名、添加注释 |
13 | | -- 支持代码高亮(使用[highlight.js](https://highlightjs.org/)) |
14 | | -- 支持导出TypeScript Interfaces |
15 | | -- 支持自定义导出文件路径 |
16 | | -- Flutter Model解析兼容了服务端返回string/int/double时数据类型混用的情况 |
17 | | -- 兼容服务端返回“id”字段 |
18 | | -- 支持类驼峰命名 |
19 | | - |
20 | | -- Support OC / Swift / Dart / TypeScript |
21 | | -- Supports one-click generation of model files through URL links or json strings |
22 | | -- Compatible with YYModel / MJExtension analysis |
| 8 | + |
| 9 | +- [x] 支持**Objective-C** / **Swift** / **Dart** / **TypeScript**等多种语言 |
| 10 | +- [x] 支持通过`URL`链接或`json`字符串一键生成model文件 |
| 11 | +- [x] 兼容`YYModel` / `MJExtension` / `HandyJSON`解析 |
| 12 | +- [x] 支持字符串加密(可设置不同的密钥,开发者可自行修改加密算法) |
| 13 | +- [x] 支持自定义model父类名、自定义model前缀、自定义作者名、添加注释 |
| 14 | +- [x] 支持代码高亮(使用[highlight.js](https://highlightjs.org/)) |
| 15 | +- [x] 支持导出`TypeScript Interfaces` |
| 16 | +- [x] 支持自定义导出文件路径 |
| 17 | +- [x] `Flutter Model`解析兼容了服务端返回`string/int/double`时数据类型混用的情况 |
| 18 | +- [x] 兼容服务端返回“id”字段 |
| 19 | +- [x] 支持类驼峰命名 |
| 20 | + |
| 21 | +- Support **Objective-C** / **Swift** / **Dart** / **TypeScript** |
| 22 | +- Supports one-click generation of model files through `URL` links or `json` strings |
| 23 | +- Compatible with `YYModel` / `MJExtension` / `HandyJSON` analysis |
23 | 24 | - Support string encryption (different keys can be set, developers can modify the encryption algorithm) |
24 | 25 | - Support custom model superclass name, custom model prefix, custom author name, add comments |
25 | 26 | - Support code highlighting(It uses [highlight.js](https://highlightjs.org/) as it core) |
26 | | -- Support for exporting TypeScript Interfaces |
| 27 | +- Support for exporting `TypeScript Interfaces` |
27 | 28 | - Support custom output folder path |
28 | | -- Flutter model parsing is compatible with mixed data types when the server returns string / int / double |
| 29 | +- `Flutter model` parsing is compatible with mixed data types when the server returns string / int / double |
29 | 30 | - Compatible server returns "id" field |
30 | 31 | - Supports hump naming |
31 | 32 |
|
| 33 | +### Usage |
32 | 34 |
|
33 | | - |
| 35 | +> * 方式一:直接下载软件安装 [](https://github.com/Xcoder1011/SKGenerateModelTool/blob/master/SKGenerateModelTool.dmg) |
| 36 | +> * 方式二:下载代码运行 |
34 | 37 |
|
35 | 38 |
|
36 | | -###### 生成Flutter Dart Model |
| 39 | +### Objective-C |
37 | 40 |
|
38 | | -``` |
39 | | -// |
40 | | -// news_response.dart |
41 | | -// SKGenerateModelTool |
42 | | -// |
43 | | -// Created by wushangkun on 2021/01/29. |
44 | | -// Copyright © 2021 SKGenerateModelTool. All rights reserved. |
45 | | -// |
46 | | -
|
47 | | -part 'news_response.m.dart'; |
48 | | -
|
49 | | -class NewsResponse { |
50 | | - List<SKDataModel> data; |
51 | | - String msg; // success |
52 | | - int code; // 200 |
53 | | -
|
54 | | - NewsResponse fromJson(Map<String, dynamic> json) => _$NewsResponseFromJson(json, this); |
55 | | - Map<String, dynamic> toJson() => _$NewsResponseToJson(this); |
56 | | -} |
57 | | -
|
58 | | -class SKDataModel { |
59 | | - String title; |
60 | | - String source; // 环球网资讯 |
61 | | - String imgsrc; |
62 | | -
|
63 | | - SKDataModel fromJson(Map<String, dynamic> json) => _$SKDataModelFromJson(json, this); |
64 | | - Map<String, dynamic> toJson() => _$SKDataModelToJson(this); |
65 | | -} |
| 41 | + |
66 | 42 |
|
67 | | -``` |
| 43 | +### Swift |
68 | 44 |
|
69 | | -实现文件 |
| 45 | + |
70 | 46 |
|
71 | | -``` |
72 | | -// |
73 | | -// news_response.m.dart |
74 | | -// SKGenerateModelTool |
75 | | -// |
76 | | -// Created by wushangkun on 2021/01/29. |
77 | | -// Copyright © 2021 SKGenerateModelTool. All rights reserved. |
78 | | -// |
79 | | -
|
80 | | -part of 'news_response.dart'; |
81 | | -
|
82 | | -NewsResponse _$NewsResponseFromJson(Map<String, dynamic> json, NewsResponse instance) { |
83 | | - if(json['data'] != null) { |
84 | | - instance.data = new List<SKDataModel>(); |
85 | | - (json['data'] as List).forEach((v) { |
86 | | - instance.data.add(new SKDataModel().fromJson(v)); |
87 | | - }); |
88 | | - } |
89 | | - if(json['msg'] != null) { |
90 | | - instance.msg = json['msg']?.toString(); |
91 | | - } |
92 | | - if(json['code'] != null) { |
93 | | - final code = json['code']; |
94 | | - if(code is String) { |
95 | | - instance.code = int.parse(code); |
96 | | - } else { |
97 | | - instance.code = code?.toInt(); |
98 | | - } |
99 | | - } |
100 | | - return instance; |
101 | | -} |
102 | | -
|
103 | | -Map<String, dynamic> _$NewsResponseToJson(NewsResponse instance) { |
104 | | - final Map<String, dynamic> json = new Map<String, dynamic>(); |
105 | | - if(instance.data != null) { |
106 | | - json['data'] = instance.data.map((v) => v.toJson()).toList(); |
107 | | - } |
108 | | - json['msg'] = instance.msg; |
109 | | - json['code'] = instance.code; |
110 | | - return json; |
111 | | -} |
112 | | -
|
113 | | -SKDataModel _$SKDataModelFromJson(Map<String, dynamic> json, SKDataModel instance) { |
114 | | - if(json['title'] != null) { |
115 | | - instance.title = json['title']?.toString(); |
116 | | - } |
117 | | - if(json['source'] != null) { |
118 | | - instance.source = json['source']?.toString(); |
119 | | - } |
120 | | - if(json['imgsrc'] != null) { |
121 | | - instance.imgsrc = json['imgsrc']?.toString(); |
122 | | - } |
123 | | - return instance; |
124 | | -} |
125 | | -
|
126 | | -Map<String, dynamic> _$SKDataModelToJson(SKDataModel instance) { |
127 | | - final Map<String, dynamic> json = new Map<String, dynamic>(); |
128 | | - json['title'] = instance.title; |
129 | | - json['source'] = instance.source; |
130 | | - json['imgsrc'] = instance.imgsrc; |
131 | | - return json; |
132 | | -} |
| 47 | +### Dart |
133 | 48 |
|
134 | | -``` |
| 49 | + |
| 50 | + |
| 51 | +### TypeScript Interfaces |
135 | 52 |
|
136 | | -###### Flutter Model header |
137 | | - |
| 53 | + |
138 | 54 |
|
139 | | -###### TypeScript Interfaces |
140 | | - |
| 55 | +### 字符串加密示例 |
141 | 56 |
|
142 | | -###### 字符串加密示例 |
143 | 57 |  |
144 | 58 |
|
145 | 59 | 加密后的内容添加到项目中(声明和定义可以分别放.h和.m),因为代码依赖SKEncryptString结构体,所以需要导入头文件**SKEncryptHeader.h**引用。 |
@@ -206,5 +120,3 @@ const SKEncryptString * const _3908173925 = &(SKEncryptString){ |
206 | 120 | Tip:本工具仅用到简单的XOR加密算法,开发者可自行下载项目进行加密算法修改,另外也可直接下载项目里的dmg文件进行安装使用。 |
207 | 121 |
|
208 | 122 | - 简书地址:[https://www.jianshu.com/p/a2ee31a04252](https://www.jianshu.com/p/a2ee31a04252) |
209 | | - |
210 | | - |
0 commit comments